<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * 订单查询类
 * @package  module/base/bill
 * @author   allen.qiang
 * @version 1.0
 */
quanli_require('module/base/system/sysUser.class.php');
class billSearch {

    /**
     * 查询订单主表信息
     * @param array $arg_array
     * @return null|array
     */
    public function searchBillInfo( &$arg_array ) {

        global $G_SHOP;

        //sql字符串
        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();



        if(isset($arg_array['cityid']) && !empty($arg_array['cityid'])){
            $cityID_1= $arg_array['cityid'];
            $sql .= " AND deliver_cityid in ($cityID_1)";
        }

        //试吃订单谁否审核
        if(isset($arg_array['bill_status_9']) && !empty($arg_array['bill_status_9'])){
            if($arg_array['bill_status_9']=='no'){
                $sql .= ' AND bill_status = ?';
                $params_type .= 'i';
                $params_array[] = 0;
            }else{
                $sql .= ' AND bill_status > ?';
                $params_type .= 'i';
                $params_array[] = 0;
            }

        }

        //试吃订单查询大客户公司名称
        if(isset($arg_array['company_name']) && !empty($arg_array['company_name'])){
            $comSql1="select pcustID FROM  company_master where company_name like '%".$arg_array['company_name']."%'";
            $count_array = &$G_SHOP->DBCA->stmt_query($comSql1);
            foreach($count_array as $ct){
                $zc[]=$ct->pcustID;//企业客户对应的普通客户ID
            }
            $pcustStr1 = implode(',',$zc);
            $sql .= " AND pcustID in ($pcustStr1)";


        }
        //试吃订单部门查询
        if(isset($arg_array['search_departmentID']) && !empty($arg_array['search_departmentID'])){
            $comSql="select pcustID FROM  company_master where departmentID =?";
            $count_array = &$G_SHOP->DBCA->stmt_query($comSql,'s',$arg_array['search_departmentID']);
            foreach($count_array as $cc){
                $zt[]=$cc->pcustID;//企业客户对应的普通客户ID
            }
            $pcustStr2 = implode(',',$zt );
            $sql .= " AND pcustID in ($pcustStr2)";

        }
        //试吃订单销售员查询
        if(isset($arg_array['userID'])&& !empty($arg_array['userID'])){
            $comSql="select pcustID FROM  company_master where userID =?";
            $count_array = &$G_SHOP->DBCA->stmt_query($comSql,'s',$arg_array['userID']);
            foreach($count_array as $xc){
                $xt[]=$xc->pcustID;//企业客户对应的普通客户ID
            }

            $pcustStr3 = implode(',',$xt );
            $sql .= " AND pcustID in ($pcustStr3)";
        }


        //订单号
        if (isset($arg_array['bill_no']) && !empty($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_no'];
        }

        //订单编号
        if (isset($arg_array['bill_code']) && !empty($arg_array['bill_code'])) {
            //mod by allen.qiang 20150507 MK-FUN-1014-MCAKE-订单查询优化方案 start
            //$sql .= ' AND bill_code LIKE ?';
            $sql .= ' AND bill_code_reverse LIKE ?';
            $params_type .= 's';
            //$params_array[] = '%'.trim($arg_array['bill_code']);
            $params_array[] = strrev(trim($arg_array['bill_code'])).'%';
            //mod by allen.qiang 20150507 MK-FUN-1014-MCAKE-订单查询优化方案 end
        }

        //会员号
        if (isset($arg_array['pcustID']) && is_numeric($arg_array['pcustID'])) {
            $sql .= ' AND pcustID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['pcustID'];
        }

        //会员名
        if (isset($arg_array['custID']) && !empty($arg_array['custID'])) {
            //mod by allen.qiang 20150422 订单查询界面会员名输入查询优化  start
            //$sql .= ' AND custID = ?';
            $sql .= ' AND pcustID = (SELECT pcustID FROM cust_master WHERE custID = ?) ';
            //mod by allen.qiang 20150422 订单查询界面会员名输入查询优化  end
            $params_type .= 's';
            $params_array[] = $arg_array['custID'];
        }

        //下单开始日期
        if (isset($arg_array['startDate']) && !empty($arg_array['startDate'])) {
            $sql .= ' AND createTime > ?';
            $params_type .= 's';
            $params_array[] = $arg_array['startDate'].' 00:00:00';
        }

        //下单结束日期
        if (isset($arg_array['endDate']) && !empty($arg_array['endDate'])) {
            $sql .= ' AND createTime < ?';
            $params_type .= 's';
            $params_array[] = $arg_array['endDate'].' 23:59:59';
        }

        //收货人
        if (isset($arg_array['deliver_name']) && !empty($arg_array['deliver_name'])) {
            $sql .= ' AND deliver_name = ?';
            $params_type .= 's';
            $params_array[] = encryptD($arg_array['deliver_name']);
        }





        //配送方式
        if (isset($arg_array['sendTypeID']) && is_numeric($arg_array['sendTypeID'])) {
            $sql .= ' AND sendTypeID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['sendTypeID'];
        }

        //支付状态
        if (isset($_REQUEST['pay_status']) && in_array($_REQUEST['pay_status'],array('0',1,2))) {
            $sql .= ' AND pay_status = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['pay_status'];
        }

        //订单状态
        if (isset($arg_array['bill_status']) && in_array($arg_array['bill_status'],array('0', 1, 2, 3, 4, 5, 6, 7, 10))) {
            $sql .= ' AND bill_status = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['bill_status'];
        }

        //订单平台
        if (isset($arg_array['billPlatform']) && is_numeric($arg_array['billPlatform'])) {
            $sql .= ' AND billPlatform = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billPlatform'];
        }
        else if(isset($arg_array['billPlatform']) && $arg_array['billPlatform'] == 'all')
        {
            $sql .= ' AND billPlatform != 3 ';
        }
        //订单渠道
        if (isset($arg_array['billChannel']) && is_numeric($arg_array['billChannel'])) {
            $sql .= ' AND billChannel = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billChannel'];
        }

        //订单类型
        if (isset($arg_array['billType']) && is_numeric($arg_array['billType'])) {
            $sql .= ' AND billType = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billType'];
        }

        //索要发票
        if (isset($arg_array['invoice']) && is_numeric($arg_array['invoice'])) {
            $sql .= ' AND invoice = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['invoice'];
        }

        //是否开票
        if (isset($arg_array['is_the_invoice']) && is_numeric($arg_array['is_the_invoice'])) {
            $sql .= ' AND is_the_invoice = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['is_the_invoice'];
        }

        //支付方式
        if (isset($arg_array['pay_type']) && in_array($arg_array['pay_type'],array(1,2,3))) {
            $sql .= ' AND pay_type = ?';
            $params_type .= 'd';
            $params_array[] = $arg_array['pay_type'];
        }

        //配送站
        if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
            $sql .= ' AND distribution_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_id'];
        }

        //配送状态
        if (isset($arg_array['deliver_status']) && in_array($arg_array['deliver_status'],array('0',1,2,3))) {
            $sql .= ' AND deliver_status = ?';
            $params_type .= 'd';
            $params_array[] = $arg_array['deliver_status'];
        }

        //省市区查询
        if (isset($arg_array['deliver_provinceid']) && quanli_is_int($arg_array['deliver_provinceid'])) {
            $sql .= ' AND deliver_provinceid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_provinceid'];
        }

        if (isset($arg_array['deliver_cityid']) && quanli_is_int($arg_array['deliver_cityid'])) {
            $sql .= ' AND deliver_cityid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_cityid'];
        }

        if (isset($arg_array['deliver_countyid']) && quanli_is_int($arg_array['deliver_countyid'])) {
            $sql .= ' AND deliver_countyid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_countyid'];
        }

        //配送时间查询
        if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
            $sql .= ' AND send_date = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_date'];
        }

        //配送开始时间
        if (isset($arg_array['send_start_time']) && !empty($arg_array['send_start_time'])) {
            $sql .= ' AND send_start_time >= ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time'];
        }

        //配送结束时间
        if (isset($arg_array['send_start_time_end']) && !empty($arg_array['send_start_time_end'])) {
            $sql .= ' AND send_start_time <= ?  ';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time_end'];
        }

        //退货状态
        if (isset($arg_array['withdraw_status']) && is_numeric($arg_array['withdraw_status']) ) {
            if ($arg_array['withdraw_status'] == 1) {
                $sql .= ' AND bill_withdrawAmount < bill_totalAmount AND bill_withdrawAmount > 0 ';
            } else if ($arg_array['withdraw_status'] == 2) {
                $sql .= ' AND bill_withdrawAmount = bill_totalAmount AND bill_withdrawAmount > 0 ';
            } else {
                $sql .= ' AND bill_withdrawAmount = 0 ';
            }
        }

        //手机号码
        if (isset($arg_array['deliver_mobile']) && !empty($arg_array['deliver_mobile'])) {
            $sql .= ' AND deliver_mobile = ?';
            $params_type .= 's';
            $params_array[] = encryptD($arg_array['deliver_mobile']);
        }

        //现金卡号
        if (isset($arg_array['card_no']) && !empty($arg_array['card_no'])) {
            $sql .= ' AND card_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%' . $arg_array['card_no'] . '%';
        }

        //优惠券号
        if (isset($arg_array['coupon_no']) && !empty($arg_array['coupon_no'])) {
            $sql .= ' AND coupon_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%' . $arg_array['coupon_no'] . '%';
        }

        //代付订单
        if (isset($arg_array['paying_agent_str']) && !empty($arg_array['paying_agent_str'])) {
            $sql .= ' AND paying_agent_str LIKE ?';
            $params_type .= 's';
            $params_array[] = '%' . $arg_array['paying_agent_str'] . '%';
        }

        //add by allen.qiang 20141024 按订单地址支持模糊查询 --start
        //收货地址
        if (isset($arg_array['deliver_address_str']) && !empty($arg_array['deliver_address_str'])) {
            $sql .= ' AND deliver_address LIKE ? ';
            $params_type .= 's';
            $params_array[] = '%' . encrypt_paramD( $arg_array['deliver_address_str']) . '%';
        }
        //add by allen.qiang 20141024 按订单地址支持模糊查询 --end
        //add by JunHui.Li 20150202  按顺丰运单号查询  --start
        //顺丰运单号
        if (isset($arg_array['external_bill_str']) && !empty($arg_array['external_bill_str'])) {
            $sql .= ' AND external_bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['external_bill_str'];
        }
        //add by JunHui.Li 20150202  按顺丰运单号查询  --end
        //商品名称
        if (isset($arg_array['goods_name_str']) && !empty($arg_array['goods_name_str'])) {
            $sql .= ' AND goods_name_str LIKE ?';
            $params_type .= 's';
            $params_array[] = '%' . $arg_array['goods_name_str'] . '%';
        }

        if (isset($arg_array['creator']) && !empty($arg_array['creator'])) {
            $sql .= ' AND creator = ? ';
            $params_type .= 's';
            $params_array[] = $arg_array['creator'];
        }

        if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
            $sql .= $arg_array['extend'];
        }

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }


        try {

            if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                //统计数量
                $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_master' . $sql;
                $count_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
                $item_count = $count_array[0]->item_count;
                if ($item_count == 0) {
                    $arg_array['count'] = 0;
                    return null;
                }

                $arg_array['count'] = $item_count;

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                //分页
                if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                    $arg_array['page'] = 1;

                $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);

            } else {

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

            }

            //查询分类信息
            //mod by allen.qiang 20141111 FUN-BK-0022-配送部自购业务需求(新增退货金额、配送自购金额两个字段) --start
            // $search_sql = 'SELECT * FROM bill_master' . $sql;
            $search_sql='SELECT bill_master.*,
                        (SELECT SUM(return_pay) FROM bill_return_pay WHERE payTypeID NOT IN(2,3) AND return_no IN ( SELECT return_no FROM bill_return WHERE return_status IN(2,3,5)
                        AND bill_code=bill_master.`bill_code`)) AS return_price,
                        (SELECT SUM(purchase_price) FROM bill_return WHERE return_type=3 AND return_status=5 AND bill_code=bill_master.`bill_code`)AS purchase_price
                     FROM bill_master ' . $sql;
            //mod by allen.qiang 20141111 FUN-BK-0022-配送部自购业务需求(新增退货金额、配送自购金额两个字段) --end

            $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);

            if (!$temp_item_array) {
                return null;
            }

            foreach ($temp_item_array as $bill) {

                //退货状态
                if( $bill->bill_withdrawAmount == $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '全部退货';
                }elseif ( $bill->bill_withdrawAmount > 0 && $bill->bill_withdrawAmount < $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '部分退货';
                }else{
                    $bill->bill_withdraw_name = '未退货';
                }

                $item_array[] = array(
                    //订单信息
                    'bill_no' => (string)$bill->bill_no,
                    'bill_code' => (string)$bill->bill_code,
                    'uuid' => $bill->uuid,
                    'timeStamp' => $bill->timeStamp,
                    'creator' => $bill->creator,
                    'createTime' => $bill->createTime,
                    'pcustID' => $bill->pcustID,
                    'custID' => $bill->custID,
                    'bill_status' => $bill->bill_status,
                    'billPlatform' => $bill->billPlatform,
                    'billPlatformName' => $GLOBALS['bill_platform'][$bill->billPlatform],
                    'billChannel' => $bill->billChannel,
                    'billChannelName' => $GLOBALS['bill_channel'][$bill->billChannel],
                    'billType' => $bill->billType,
                    'billTypeName' => $GLOBALS['bill_type'][$bill->billType]['name'],
                    'bill_status_name' => $GLOBALS['backend_bill_status'][$bill->bill_status],
                    'shop_bill_status_name' => $GLOBALS['shop_bill_status'][$bill->bill_status],
                    'bill_cancel' => $bill->bill_cancel,
                    'bill_cancelTime' => $bill->bill_cancelTime,
                    'bill_totalMoney' => $bill->bill_totalMoney,
                    'bill_totalPaid' => $bill->bill_totalPaid,
                    'bill_totalPoints' => $bill->bill_totalPoints,
                    'bill_pointsPrice' => $bill->bill_pointsPrice,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'bill_withdraw_name' => $bill->bill_withdraw_name,
                    'bill_subtract_money' => $bill->bill_subtract_money,
                    'bill_coupon_money' => $bill->bill_coupon_money,
                    'bill_card_money' => $bill->bill_card_money,
                    'bill_points_money' => $bill->bill_points_money,
                    'bill_balance_money' => $bill->bill_balance_money,
                    'bill_online_money' => $bill->bill_online_money,
                    'bill_accessories_money' => $bill->bill_accessories_money,
                    'bill_receivable_money' => $bill->bill_receivable_money,
                    'bill_unreceived_money' =>$bill->bill_unreceived_money,//add by allen.qiang 去零金额
                    'bill_received_money' =>$bill->bill_received_money,
                    'bill_money' =>$bill->bill_money,
                    'bill_paying_agent_money' =>$bill->bill_paying_agent_money,
                    'tableware_amount' =>$bill->tableware_amount,
                    'candle_amount' =>$bill->candle_amount,
                    'is_urgent' => $bill->is_urgent,
                    'paying_agent_str'=>$bill->paying_agent_str,
                    'bill_completionTime'=>$bill->bill_completionTime,
                    'goods_name_str'=>$bill->goods_name_str,
                    'special_status'=>$bill->special_status,
                    'numPeo'=>$bill->numPeo,

                    //收货人信息
                    'deliverid' => $bill->deliverid,
                    'deliver_name' => decryptD($bill->deliver_name),
                    'deliver_province' => $bill->deliver_province,
                    'deliver_provinceid' => $bill->deliver_provinceid,
                    'deliver_city' => $bill->deliver_city,
                    'deliver_cityid' => $bill->deliver_cityid,
                    'deliver_county' => $bill->deliver_county,
                    'deliver_countyid' => $bill->deliver_countyid,
                    'deliver_address' => decryptD($bill->deliver_address),
                    'deliver_all_address' => $bill->deliver_province . $bill->deliver_city . $bill->deliver_county . decryptD($bill->deliver_address),
                    'deliver_postalCode' => $bill->deliver_postalCode,
                    'deliver_mobile' => decryptD($bill->deliver_mobile),
                    'deliver_phone' => decryptD($bill->deliver_phone),

                    //配送

                    'distribution_id' => $bill->distribution_id,//配送站ID
                    'distribution_name' => $bill->distribution_name,//配送站名称
                    'distribution_technician_id' => $bill->distribution_technician_id,//配送员ID
                    'distribution_technicia' => $bill->distribution_technicia,//配送员名称

                    'sendTypeID' => $bill->sendTypeID, //配送方式ID
                    'sendTypeName' => $bill->sendTypeName, //配送方式名称
                    'send_region_name' => $bill->send_region_name, //配送区域名称
                    'send_region_id' => $bill->send_region_id, //配送区域ID
                    'deliver_fee' => $bill->deliver_fee, //应收运费
                    'deliver_feePaid' => $bill->deliver_feePaid, //实收运费
                    'deliver_status' => $bill->deliver_status, //配送状态
                    'deliver_status_name' => $GLOBALS['deliver_status'][$bill->deliver_status], //配送状态
                    'deliver_time' => $bill->deliver_time, //配送状态变化时间
                    'send_date' => $bill->send_date,
                    'send_start_time' => $bill->send_start_time,
                    'send_end_time' => $bill->send_end_time,

                    //付款
                    'pay_status' => $bill->pay_status, //付款状态
                    'pay_status_name' => $GLOBALS['pay_status'][$bill->pay_status], //付款方式名称
                    'payed_time' => $bill->payed_time, //付款时间
                    'pay_type' => $bill->pay_type, //支付方式类型
                    'payTypeID' => $bill->payTypeID, //支付方式ID
                    'payTypeName' => $bill->payTypeName, //支付方式名称
                    'payment_method_id' => $bill->payment_method_id, //付款方式id
                    'payment_method_name' => $bill->payment_method_name, //付款方式名称

                    //发票信息
                    'invoice' => $bill->invoice,
                    'invoiceID' => $bill->invoiceID,
                    'invoice_type' => $bill->invoice_type,
                    'invoice_title_type' => $bill->invoice_title_type,
                    'invoice_title' => $bill->invoice_title,
                    'invoice_content_id' => $bill->invoice_content_id,
                    'invoice_content' => $bill->invoice_content,
                    'invoice_amount' => $bill->invoice_amount,
                    'invoice_number' => $bill->invoice_number,
                    'is_the_invoice' => $bill->is_the_invoice,
                    'is_comment' => $bill->is_comment,

                    'auth_alter' => $bill->auth_alter,
                    'remark' => $bill->remark,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'billPromotion' => $bill->billPromotion,
                    'bill_other_address_pay' => $bill->bill_other_address_pay,
                    'external_bill_no' => $bill->external_bill_no,
                    'special_status ' =>$bill->special_status,
                    'coupon_code ' =>$bill->coupon_code,
                    //add by allen.qiang 20141110 FUN-BK-0022-配送部自购业务需求 --start
                    'return_price' => $bill->return_price,
                    'purchase_price' => $bill->purchase_price
                    //add by allen.qiang 20141110 FUN-BK-0022-配送部自购业务需求 --end
                );
            }

            return $item_array;

        } catch (Exception $e) {

            error_log($e->getMessage());
            return null;
        }

    }


    /**
     * 查询订单主表信息
     * @param array $arg_array
     * @return null|array
     */
    public function searchBillInfo9( &$arg_array ) {

        global $G_SHOP;

        //sql字符串
        $sql = '';
        $slqs='';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();


        if(isset($arg_array['cityid']) && !empty($arg_array['cityid'])){
            $cityID_1= $arg_array['cityid'];
            $sql .= " AND deliver_cityid in ($cityID_1)";
        }
        //试吃订单谁否审核
        if(isset($arg_array['bill_status_9']) && !empty($arg_array['bill_status_9'])){
            if($arg_array['bill_status_9']=='no'){
                $sql .= ' AND bill_status = ?';
                $params_type .= 'i';
                $params_array[] = 0;
            }else{
                $sql .= ' AND bill_status > ?';
                $params_type .= 'i';
                $params_array[] = 0;
            }

        }
        //部门ID
        if (isset($arg_array['departmentID']) && !empty($arg_array['departmentID']) && $arg_array['departmentID']!="") {
            $slqs.= ' AND departmentID in ('.$arg_array['departmentID'].')';
        }
        //销售员ID
        if (isset($arg_array['userID']) && !empty($arg_array['userID'])) {
            $slqs.= " AND userID ='".$arg_array['userID']."'";
        }
        //拓展字段
        if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
            $login_session =  $G_SHOP->sessionCache_get ( 'PS_LOGIN_SESSION' );
            $str_departmentID= strstr($arg_array['extend'],"(");
            $str_departmentID=str_replace('(',',',$str_departmentID) ;
            $str_departmentID=str_replace(')',',',$str_departmentID) ;

            if(strpos($str_departmentID,",".$login_session['department'].",")>-1){
                $str_departmentID=str_replace(','.$login_session['department'].',',',',$str_departmentID) ;
                $str_departmentID=trim($str_departmentID,',');
                if($str_departmentID==""){
                    $slqs.=" AND (userID='".$G_SHOP->currentUserID."' OR (departmentID=".$login_session['department']." AND userID='".$G_SHOP->currentUserID."') )";
                }else{
                    $slqs.=" AND (userID='".$G_SHOP->currentUserID."' OR (departmentID IN ( ".$str_departmentID." ) OR departmentID=".$login_session['department']." ) )";
                }
            }else{
                $slqs.= $arg_array['extend'];
            }
        }

        //试吃订单查询大客户公司名称
        if(isset($arg_array['company_name']) && !empty($arg_array['company_name'])){
            $slqs.=" and company_name like '%".$arg_array['company_name']."%'";
        }
        $comSql1="select pcustID FROM  company_master where 1=1 ".$slqs;

        $count_array = &$G_SHOP->DBCA->stmt_query($comSql1);
        foreach($count_array as $ct){
            $zc[]=$ct->pcustID;//企业客户对应的普通客户ID
        }
        $pcustStr1 = implode(',',$zc);

        $sql .= " AND pcustID in ($pcustStr1)";

        /* //试吃订单部门查询
          if(isset($arg_array['search_departmentID']) && !empty($arg_array['search_departmentID'])){
              $comSql="select pcustID FROM  company_master where departmentID =?";
              $count_array = &$G_SHOP->DBCA->stmt_query($comSql,'s',$arg_array['search_departmentID']);
              foreach($count_array as $cc){
                  $zt[]=$cc->pcustID;//企业客户对应的普通客户ID
              }
              $pcustStr2 = implode(',',$zt );
              $sql .= " AND pcustID in ($pcustStr2)";

          }
          //试吃订单销售员查询
          if(isset($arg_array['userID'])&& !empty($arg_array['userID'])){
              $comSql="select pcustID FROM  company_master where userID =?";
              $count_array = &$G_SHOP->DBCA->stmt_query($comSql,'s',$arg_array['userID']);
              foreach($count_array as $xc){
                  $xt[]=$xc->pcustID;//企业客户对应的普通客户ID
              }

              $pcustStr3 = implode(',',$xt );
              $sql .= " AND pcustID in ($pcustStr3)";
          }*/


        //订单号
        if (isset($arg_array['bill_no']) && !empty($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_no'];
        }

        //订单编号
        if (isset($arg_array['bill_code']) && !empty($arg_array['bill_code'])) {
            $sql .= ' AND bill_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%'.trim($arg_array['bill_code']);
        }

        //会员号
        if (isset($arg_array['pcustID']) && is_numeric($arg_array['pcustID'])) {
            $sql .= ' AND pcustID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['pcustID'];
        }

        //会员名
        if (isset($arg_array['custID']) && !empty($arg_array['custID'])) {
            $sql .= ' AND custID = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['custID'];
        }

        //下单开始日期
        if (isset($arg_array['startDate']) && !empty($arg_array['startDate'])) {
            $sql .= ' AND createTime > ?';
            $params_type .= 's';
            $params_array[] = $arg_array['startDate'].' 00:00:00';
        }

        //下单结束日期
        if (isset($arg_array['endDate']) && !empty($arg_array['endDate'])) {
            $sql .= ' AND createTime < ?';
            $params_type .= 's';
            $params_array[] = $arg_array['endDate'].' 23:59:59';
        }

        //收货人
        if (isset($arg_array['deliver_name']) && !empty($arg_array['deliver_name'])) {
            $sql .= ' AND deliver_name = ?';
            $params_type .= 's';
            $params_array[] = encryptD($arg_array['deliver_name']);
        }

        //配送方式
        if (isset($arg_array['sendTypeID']) && is_numeric($arg_array['sendTypeID'])) {
            $sql .= ' AND sendTypeID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['sendTypeID'];
        }

        //支付状态
        if (isset($_REQUEST['pay_status']) && in_array($_REQUEST['pay_status'],array('0',1,2))) {
            $sql .= ' AND pay_status = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['pay_status'];
        }

        //订单状态
        if (isset($arg_array['bill_status']) && in_array($arg_array['bill_status'],array('0', 1, 2, 3, 4, 5, 6, 7, 10))) {
            $sql .= ' AND bill_status = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['bill_status'];
        }

        //订单平台
        if (isset($arg_array['billPlatform']) && is_numeric($arg_array['billPlatform'])) {
            $sql .= ' AND billPlatform = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billPlatform'];
        }

        //订单渠道
        if (isset($arg_array['billChannel']) && is_numeric($arg_array['billChannel'])) {
            $sql .= ' AND billChannel = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billChannel'];
        }

        //订单类型
        if (isset($arg_array['billType']) && is_numeric($arg_array['billType'])) {
            $sql .= ' AND billType = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billType'];
        }

        //索要发票
        if (isset($arg_array['invoice']) && is_numeric($arg_array['invoice'])) {
            $sql .= ' AND invoice = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['invoice'];
        }

        //是否开票
        if (isset($arg_array['is_the_invoice']) && is_numeric($arg_array['is_the_invoice'])) {
            $sql .= ' AND is_the_invoice = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['is_the_invoice'];
        }

        //支付方式
        if (isset($arg_array['pay_type']) && in_array($arg_array['pay_type'],array(1,2,3))) {
            $sql .= ' AND pay_type = ?';
            $params_type .= 'd';
            $params_array[] = $arg_array['pay_type'];
        }

        //配送站
        if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
            $sql .= ' AND distribution_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_id'];
        }

        //配送状态
        if (isset($arg_array['deliver_status']) && in_array($arg_array['deliver_status'],array('0',1,2,3))) {
            $sql .= ' AND deliver_status = ?';
            $params_type .= 'd';
            $params_array[] = $arg_array['deliver_status'];
        }

        //省市区查询
        if (isset($arg_array['deliver_provinceid']) && quanli_is_int($arg_array['deliver_provinceid'])) {
            $sql .= ' AND deliver_provinceid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_provinceid'];
        }

        if (isset($arg_array['deliver_cityid']) && quanli_is_int($arg_array['deliver_cityid'])) {
            $sql .= ' AND deliver_cityid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_cityid'];
        }

        if (isset($arg_array['deliver_countyid']) && quanli_is_int($arg_array['deliver_countyid'])) {
            $sql .= ' AND deliver_countyid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_countyid'];
        }

        //配送时间查询
        if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
            $sql .= ' AND send_date = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_date'];
        }

        //配送开始时间
        if (isset($arg_array['send_start_time']) && !empty($arg_array['send_start_time'])) {
            $sql .= ' AND send_start_time >= ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time'];
        }

        //配送结束时间
        if (isset($arg_array['send_start_time_end']) && !empty($arg_array['send_start_time_end'])) {
            $sql .= ' AND send_start_time <= ?  ';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time_end'];
        }

        //退货状态
        if (isset($arg_array['withdraw_status']) && is_numeric($arg_array['withdraw_status']) ) {
            if ($arg_array['withdraw_status'] == 1) {
                $sql .= ' AND bill_withdrawAmount < bill_totalAmount AND bill_withdrawAmount > 0 ';
            } else if ($arg_array['withdraw_status'] == 2) {
                $sql .= 'AND bill_withdrawAmount = bill_totalAmount AND bill_withdrawAmount > 0 ';
            } else {
                $sql .= ' AND bill_withdrawAmount = 0 ';
            }
        }

        //手机号码
        if (isset($arg_array['deliver_mobile']) && !empty($arg_array['deliver_mobile'])) {
            $sql .= ' AND deliver_mobile = ?';
            $params_type .= 's';
            $params_array[] = encryptD($arg_array['deliver_mobile']);
        }

        //现金卡号
        if (isset($arg_array['card_no']) && !empty($arg_array['card_no'])) {
            $sql .= ' AND card_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%' . $arg_array['card_no'] . '%';
        }

        //优惠券号
        if (isset($arg_array['coupon_no']) && !empty($arg_array['coupon_no'])) {
            $sql .= ' AND coupon_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%' . $arg_array['coupon_no'] . '%';
        }

        //代付订单
        if (isset($arg_array['paying_agent_str']) && !empty($arg_array['paying_agent_str'])) {
            $sql .= ' AND paying_agent_str LIKE ?';
            $params_type .= 's';
            $params_array[] = '%' . $arg_array['paying_agent_str'] . '%';
        }

        //商品名称
        if (isset($arg_array['goods_name_str']) && !empty($arg_array['goods_name_str'])) {
            $sql .= ' AND goods_name_str LIKE ?';
            $params_type .= 's';
            $params_array[] = '%' . $arg_array['goods_name_str'] . '%';
        }

        /*  if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
              $sql .= $arg_array['extend'];
          }*/

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }

        try {

            if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                //统计数量
                $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_master' . $sql;
                $count_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
                $item_count = $count_array[0]->item_count;
                if ($item_count == 0) {
                    $arg_array['count'] = 0;
                    return null;
                }

                $arg_array['count'] = $item_count;

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                //分页
                if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                    $arg_array['page'] = 1;

                $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);

            } else {

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

            }

            //查询分类信息
            $search_sql = 'SELECT * FROM bill_master' . $sql;
            $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);


            if (!$temp_item_array) {
                return null;
            }

            foreach ($temp_item_array as $bill) {

                //退货状态
                if( $bill->bill_withdrawAmount == $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '全部退货';
                }elseif ( $bill->bill_withdrawAmount > 0 && $bill->bill_withdrawAmount < $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '部分退货';
                }else{
                    $bill->bill_withdraw_name = '未退货';
                }

                $item_array[] = array(
                    //订单信息
                    'bill_no' => (string)$bill->bill_no,
                    'bill_code' => (string)$bill->bill_code,
                    'uuid' => $bill->uuid,
                    'timeStamp' => $bill->timeStamp,
                    'creator' => $bill->creator,
                    'createTime' => $bill->createTime,
                    'pcustID' => $bill->pcustID,
                    'custID' => $bill->custID,
                    'bill_status' => $bill->bill_status,
                    'billPlatform' => $bill->billPlatform,
                    'billPlatformName' => $GLOBALS['bill_platform'][$bill->billPlatform],
                    'billChannel' => $bill->billChannel,
                    'billChannelName' => $GLOBALS['bill_channel'][$bill->billChannel],
                    'billType' => $bill->billType,
                    'billTypeName' => $GLOBALS['bill_type'][$bill->billType]['name'],
                    'bill_status_name' => $GLOBALS['backend_bill_status'][$bill->bill_status],
                    'shop_bill_status_name' => $GLOBALS['shop_bill_status'][$bill->bill_status],
                    'bill_cancel' => $bill->bill_cancel,
                    'bill_cancelTime' => $bill->bill_cancelTime,
                    'bill_totalMoney' => $bill->bill_totalMoney,
                    'bill_totalPaid' => $bill->bill_totalPaid,
                    'bill_totalPoints' => $bill->bill_totalPoints,
                    'bill_pointsPrice' => $bill->bill_pointsPrice,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'bill_withdraw_name' => $bill->bill_withdraw_name,
                    'bill_subtract_money' => $bill->bill_subtract_money,
                    'bill_coupon_money' => $bill->bill_coupon_money,
                    'bill_card_money' => $bill->bill_card_money,
                    'bill_points_money' => $bill->bill_points_money,
                    'bill_balance_money' => $bill->bill_balance_money,
                    'bill_online_money' => $bill->bill_online_money,
                    'bill_receivable_money' => $bill->bill_receivable_money,
                    'bill_received_money' =>$bill->bill_received_money,
                    'bill_money' =>$bill->bill_money,
                    'bill_paying_agent_money' =>$bill->bill_paying_agent_money,
                    'tableware_amount' =>$bill->tableware_amount,
                    'candle_amount' =>$bill->candle_amount,
                    'is_urgent' => $bill->is_urgent,
                    'paying_agent_str'=>$bill->paying_agent_str,
                    'bill_completionTime'=>$bill->bill_completionTime,
                    'goods_name_str'=>$bill->goods_name_str,
                    'special_status'=>$bill->special_status,

                    //收货人信息
                    'deliverid' => $bill->deliverid,
                    'deliver_name' => decryptD($bill->deliver_name),
                    'deliver_province' => $bill->deliver_province,
                    'deliver_provinceid' => $bill->deliver_provinceid,
                    'deliver_city' => $bill->deliver_city,
                    'deliver_cityid' => $bill->deliver_cityid,
                    'deliver_county' => $bill->deliver_county,
                    'deliver_countyid' => $bill->deliver_countyid,
                    'deliver_address' => decryptD($bill->deliver_address),
                    'deliver_all_address' => $bill->deliver_province . $bill->deliver_city . $bill->deliver_county . decryptD($bill->deliver_address),
                    'deliver_postalCode' => $bill->deliver_postalCode,
                    'deliver_mobile' => decryptD($bill->deliver_mobile),
                    'deliver_phone' => decryptD($bill->deliver_phone),

                    //配送

                    'distribution_id' => $bill->distribution_id,//配送站ID
                    'distribution_name' => $bill->distribution_name,//配送站名称
                    'distribution_technician_id' => $bill->distribution_technician_id,//配送员ID
                    'distribution_technicia' => $bill->distribution_technicia,//配送员名称

                    'sendTypeID' => $bill->sendTypeID, //配送方式ID
                    'sendTypeName' => $bill->sendTypeName, //配送方式名称
                    'send_region_name' => $bill->send_region_name, //配送区域名称
                    'send_region_id' => $bill->send_region_id, //配送区域ID
                    'deliver_fee' => $bill->deliver_fee, //应收运费
                    'deliver_feePaid' => $bill->deliver_feePaid, //实收运费
                    'deliver_status' => $bill->deliver_status, //配送状态
                    'deliver_status_name' => $GLOBALS['deliver_status'][$bill->deliver_status], //配送状态
                    'deliver_time' => $bill->deliver_time, //配送状态变化时间
                    'send_date' => $bill->send_date,
                    'send_start_time' => $bill->send_start_time,
                    'send_end_time' => $bill->send_end_time,

                    //付款
                    'pay_status' => $bill->pay_status, //付款状态
                    'pay_status_name' => $GLOBALS['pay_status'][$bill->pay_status], //付款方式名称
                    'payed_time' => $bill->payed_time, //付款时间
                    'pay_type' => $bill->pay_type, //支付方式类型
                    'payTypeID' => $bill->payTypeID, //支付方式ID
                    'payTypeName' => $bill->payTypeName, //支付方式名称
                    'payment_method_id' => $bill->payment_method_id, //付款方式id
                    'payment_method_name' => $bill->payment_method_name, //付款方式名称

                    //发票信息
                    'invoice' => $bill->invoice,
                    'invoiceID' => $bill->invoiceID,
                    'invoice_type' => $bill->invoice_type,
                    'invoice_title_type' => $bill->invoice_title_type,
                    'invoice_title' => $bill->invoice_title,
                    'invoice_content_id' => $bill->invoice_content_id,
                    'invoice_content' => $bill->invoice_content,
                    'invoice_amount' => $bill->invoice_amount,
                    'invoice_number' => $bill->invoice_number,
                    'is_the_invoice' => $bill->is_the_invoice,
                    'is_comment' => $bill->is_comment,

                    'auth_alter' => $bill->auth_alter,
                    'remark' => $bill->remark,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'billPromotion' => $bill->billPromotion,
                    'bill_other_address_pay' => $bill->bill_other_address_pay,
                    'external_bill_no' => $bill->external_bill_no,
                    'special_status ' =>$bill->special_status,
                    'coupon_code ' =>$bill->coupon_code,
                    'numPeo' => $bill->numPeo
                );
            }

            return $item_array;

        } catch (Exception $e) {

            error_log($e->getMessage());
            return null;
        }
    }





    /**
     * 查询订单商品信息
     * @param array $arg_array
     * @return null|array
     */
    public function searchBillGoods( $arg_array ) {

        //订单号
        if (!isset($arg_array['bill_no']) || empty($arg_array['bill_no'])) {
            return null;
        }

        global $G_SHOP;

        //sql字符串
        $sql = 'WHERE bill_no = ?';

        //参数类型字符串
        $params_type = 's';

        //参数值数组
        $params_array[] = $arg_array['bill_no'];

        //订单流水号
        if (isset($arg_array['bill_goods_no']) && is_numeric($arg_array['bill_goods_no'])) {
            $sql .= ' AND bill_goods_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_goods_no'];
        }

        //订单商品网购号
        if (isset($arg_array['goods_postID']) && is_numeric($arg_array['goods_postID'])) {
            $sql .= ' AND goods_postID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['goods_postID'];
        }

        //排序
        if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
            $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

        //查询订单商品信息
        $search_sql = 'SELECT * FROM bill_goods ' . $sql;
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();

        foreach ($temp_item_array as &$item) {
            $sql_fittings='select * from bill_goods_fittings where bill_goods_no =?';
            $bill_goods_no=$G_SHOP->DBCA->stmt_query($sql_fittings,'i',$item->bill_goods_no);
            $buy_momney=0;
            if( is_array( $bill_goods_no )){
                foreach($bill_goods_no as $bill_buy){


                    //mod by 20141028 sunqiang FUN-BK-0012 退货单默认退货金额 start
                    //配件的金额
                    //$buy_momney+=$bill_buy->buyMoney*$bill_buy->buyNum;
                    $buy_momney+= ceil( $bill_buy->buyMoney*$bill_buy->buyNum );
                    //mod by 20141028 sunqiang FUN-BK-0012 退货单默认退货金额 end

                }
            }

            $item_array[$item->bill_goods_no] = array(
                'bill_no' => (string)$item->bill_no,
                'bill_goods_no' => (string)$item->bill_goods_no,
                'goods_goodsID' => $item->goods_goodsID,
                'goods_postID' => $item->goods_postID,
                'product_code' => $item->product_code,
                'goods_name' => $item->goods_name,
                'goods_spec' => $item->goods_spec,
                'goods_amount' => $item->goods_amount,
                'goods_marketPrice' => $item->goods_marketPrice,
                'goods_storePrice' => $item->goods_storePrice,
                'goods_purchasePrice' => $item->goods_purchasePrice,
                'goods_points' => $item->goods_points,
                'goods_weight' => $item->goods_weight,
                'goods_from' => $item->goods_from,
                'goods_groupID' => $item->goods_groupID,
                'goods_status' => $item->goods_status,
                'goods_time' => $item->goods_time,
                'goods_delivercount' => $item->goods_delivercount,
                'goods_withdrawAmount' => $item->goods_withdrawAmount,
                'goods_rejectionAmount' => $item->goods_rejectionAmount,
                'goods_pointsPrice' => $item->goods_pointsPrice,
                'extra_tableware_amount' => $item->extra_tableware_amount,
                'extra_candle_amount' => $item->extra_candle_amount,
                'candle_amount' => $item->candle_amount,
                'comment_flg' => $item->comment_flg,
                'product_amount' => $item->product_amount,
                'birthday_card' => $item->birthday_card,
                'segmentation' => $item->segmentation,
                'candle' => $item->candle,
                'goods_remark' => $item->goods_remark,
                'tableware_amount' => $item->tableware_amount,
                'print_num' => $item->print_num,
                'print_operator' => $item->print_operator,
                'print_time' => $item->print_time,
                'is_voucher' => $item->is_voucher,
                'voucher_operator' => $item->voucher_operator,
                'voucher_time' => $item->voucher_time,
                'is_warehouse' => $item->is_warehouse,
                'warehouse_operator' => $item->warehouse_operator,
                'warehouse_time' => $item->warehouse_time,
                'is_busScan' => $item->is_busScan,
                'busScan_operator' => $item->busScan_operator,
                'busScan_time' => $item->busScan_time,
                'auth_alter' => $item->auth_alter,
                'buyMoney'=>$buy_momney
            );
        }

        return $item_array;

    }

    /**
     * 查询订单商品信息
     * @param $bill_no
     * @param $bill_goods_no
     * @return null
     */
    public function searchBillGoodsDetail( $bill_no, $bill_goods_no ) {

        if (!isset($bill_no, $bill_goods_no) || empty($bill_no) || empty($bill_goods_no)) {
            return null;
        }

        global $G_SHOP;

        //查询订单商品信息
        $search_sql = 'SELECT * FROM bill_goods WHERE bill_no = ? AND bill_goods_no = ?';
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, 'ss', $bill_no, $bill_goods_no);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();

        foreach ($temp_item_array as &$item) {
            $item_array[] = array(
                'bill_no' => (string)$item->bill_no,
                'bill_goods_no' => (string)$item->bill_goods_no,
                'goods_goodsID' => $item->goods_goodsID,
                'goods_postID' => $item->goods_postID,
                'product_code' => $item->product_code,
                'goods_name' => $item->goods_name,
                'goods_spec' => $item->goods_spec,
                'goods_amount' => $item->goods_amount,
                'goods_marketPrice' => $item->goods_marketPrice,
                'goods_storePrice' => $item->goods_storePrice,
                'goods_purchasePrice' => $item->goods_purchasePrice,
                'goods_points' => $item->goods_points,
                'goods_weight' => $item->goods_weight,
                'goods_from' => $item->goods_from,
                'goods_groupID' => $item->goods_groupID,
                'goods_status' => $item->goods_status,
                'goods_time' => $item->goods_time,
                'goods_delivercount' => $item->goods_delivercount,
                'goods_withdrawAmount' => $item->goods_withdrawAmount,
                'goods_rejectionAmount' => $item->goods_rejectionAmount,
                'goods_pointsPrice' => $item->goods_pointsPrice,
                'extra_tableware_amount' => $item->extra_tableware_amount,
                'extra_candle_amount' => $item->extra_candle_amount,
                'candle_amount' => $item->candle_amount,
                'comment_flg' => $item->comment_flg,
                'product_amount' => $item->product_amount,
                'birthday_card' => $item->birthday_card,
                'segmentation' => $item->segmentation,
                'candle' => $item->candle,
                'goods_remark' => $item->goods_remark,
                'tableware_amount' => $item->tableware_amount,
                'print_num' => $item->print_num,
                'print_operator' => $item->print_operator,
                'print_time' => $item->print_time,
                'is_voucher' => $item->is_voucher,
                'voucher_operator' => $item->voucher_operator,
                'voucher_time' => $item->voucher_time,
                'is_warehouse' => $item->is_warehouse,
                'warehouse_operator' => $item->warehouse_operator,
                'warehouse_time' => $item->warehouse_time,
                'is_busScan' => $item->is_busScan,
                'busScan_operator' => $item->busScan_operator,
                'busScan_time' => $item->busScan_time,
                'auth_alter' => $item->auth_alter
            );
        }

        return $item_array[0];

    }

    /**
     * 查询订单支付信息
     * @param array $arg_array
     * @return null|array
     */
    public function searchBillPay( $arg_array ) {

        if (!isset($arg_array['bill_no']) || empty($arg_array['bill_no'])) {
            return null;
        }

        global $G_SHOP;

        //sql字符串
        $sql = ' WHERE bill_no = ?';

        //参数类型字符串
        $params_type = 's';

        //参数值数组
        $params_array[] =$arg_array['bill_no'];

        //支付方式ID
        if (isset($arg_array['payTypeID']) && is_numeric($arg_array['payTypeID'])) {
            $sql .= ' AND payTypeID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['payTypeID'];
        }

        //支付方式类型
        if (isset($arg_array['type']) && is_numeric($arg_array['type'])) {
            $sql .= ' AND type = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['type'];
        }

        //排序
        if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
            $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);


        //查询分类信息
        $search_sql = 'SELECT * FROM bill_pay ' . $sql;
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();
        foreach ($temp_item_array as &$item) {
            $item_array[$item->payTypeID] = array(
                'bill_no' => $item->bill_no,
                'bill_pay_no' => $item->bill_pay_no,
                'payTypeID' => $item->payTypeID,
                'payTypeName' => $item->payTypeName,
                'type' => $item->type,
                'pay_amount' => $item->pay_amount,
                'deduct_amount' => $item->deduct_amount,
                'pay_code' => $item->pay_code,
                'pay_time' => $item->pay_time,
                'payment_method_id' => $item->payment_method_id,
                'payment_method_name' => $item->payment_method_name,
                'payment_method_type' => $item->payment_method_type,
                'receipt_amount' => $item->receipt_amount,
            );
        }

        return $item_array;

    }

    /**
     * 查询订单支付详情
     * @param array $arg_array
     * @return null|array
     */
    public function searchBillPayDetail( $arg_array ) {

        if (!isset($arg_array['bill_no']) || empty($arg_array['bill_no'])) {
            return null;
        }
        if (!isset($arg_array['payTypeID']) && !isset($arg_array['type'])) {
            return null;
        }

        global $G_SHOP;

        //sql字符串
        $sql = ' WHERE bill_no = ?';

        //参数类型字符串
        $params_type = 's';

        //参数值数组
        $params_array[] =$arg_array['bill_no'];

        //支付方式ID
        if (isset($arg_array['payTypeID']) && is_numeric($arg_array['payTypeID'])) {
            $sql .= ' AND payTypeID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['payTypeID'];
        }

        //支付方式类型
        if (isset($arg_array['type']) && is_numeric($arg_array['type'])) {
            $sql .= ' AND type = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['type'];
        }

        //查询分类信息
        $search_sql = 'SELECT * FROM bill_pay ' . $sql;
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
        if (!$temp_item_array) {
            return null;
        }

        return array(
            'timeStamp' => $temp_item_array[0]->timeStamp,
            'creator' => $temp_item_array[0]->creator,
            'createTime' => $temp_item_array[0]->createTime,
            'bill_no' => $temp_item_array[0]->bill_no,
            'bill_pay_no' => $temp_item_array[0]->bill_pay_no,
            'payTypeID' => $temp_item_array[0]->payTypeID,
            'payTypeName' => $temp_item_array[0]->payTypeName,
            'type' => $temp_item_array[0]->type,
            'pay_amount' => $temp_item_array[0]->pay_amount,
            'deduct_amount' => $temp_item_array[0]->deduct_amount,
            'pay_code' => $temp_item_array[0]->pay_code,
            'pay_time' => $temp_item_array[0]->pay_time,
            'payment_method_id' => $temp_item_array[0]->payment_method_id,
            'payment_method_name' => $temp_item_array[0]->payment_method_name,
            'payment_method_type' => $temp_item_array[0]->payment_method_type,
            'receipt_amount' => $temp_item_array[0]->receipt_amount,
            'paid_confirm_status' => $temp_item_array[0]->paid_confirm_status,
            'paid_confirmer' => $temp_item_array[0]->paid_confirmer,
            'paid_confirm_time' => $temp_item_array[0]->paid_confirm_time
        );

    }

    /**
     * 查询订单内部留言
     * @param $arg_array
     * @return array|null
     */
    public function searchBillRemark( &$arg_array ) {

        global $G_SHOP;

        //sql字符串
        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //订单号
        if (isset($arg_array['bill_no']) && is_numeric($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_no'];
        }

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }


        try {

            if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                //统计数量
                $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_remark ' . $sql;
                $count_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
                $item_count = $count_array[0]->item_count;
                if ($item_count == 0) {
                    $arg_array['count'] = 0;
                    return null;
                }

                $arg_array['count'] = $item_count;

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                //分页
                if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                    $arg_array['page'] = 1;

                $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);

            } else {

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

            }

            //查询备注信息
            $search_sql = 'SELECT * FROM bill_remark ' . $sql;
            $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
            if (!$temp_item_array)
                return null;

            if ($temp_item_array) {
                foreach ($temp_item_array as &$item) {
                    $item_array[] = array(
                        'bill_no' => $item->bill_no,
                        'creator' => $item->creator,
                        'createTime' => $item->createTime,
                        'remark' => $item->remark
                    );
                }
            }

            return $item_array;

        } catch (Exception $e) {

            error_log($e->getMessage());
            return null;
        }

    }

    /**
     * 查询订单轨迹信息
     * @param array $arg_array
     * @return null|array
     */
    public function searchBillTrace( &$arg_array ) {

        if (!isset($arg_array['bill_no']) || empty($arg_array['bill_no'])) {
            return null;
        }

        global $G_SHOP;

        //sql字符串
        $sql = 'bill_no = ?';

        //参数类型字符串
        $params_type = 's';

        //参数值数组
        $params_array = array( $arg_array['bill_no'] );


        //订单状态
        if (isset($arg_array['bill_status']) && is_numeric($arg_array['bill_status'])) {
            $sql .= ' AND bill_status = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['bill_status'];
        }
        //MOD BY ALLEN.QIANG 20150611 排序字段使用自增长列 START
        $sql .= ' ORDER BY trace_id ASC';
        //MOD BY ALLEN.QIANG 20150611 排序字段使用自增长列 END

        //查询分类信息
        $search_sql = 'SELECT * FROM bill_trace WHERE ' . $sql;
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();
        foreach ($temp_item_array as &$item) {
            $item_array[] = array(
                'bill_no' => $item->bill_no,
                'creator' => $item->creator,
                'createTime' => $item->createTime,
                'bill_status' => $item->bill_status,
                'content' => $item->content
            );
        }

        return $item_array;

    }

    /**
     * 查询订单使用的优惠券
     * @param int $bill_no 订单号
     * @return array|null
     */
    public function searchBillUsedCoupon( $bill_no ) {

        global $G_SHOP;

        if (!isset($bill_no) || empty($bill_no)) {
            return null;
        }

        $temp_item_array = &$G_SHOP->DBCA->stmt_query('SELECT * FROM bill_use_coupon WHERE bill_no = ?', 's', $bill_no);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();
        foreach ($temp_item_array as &$item) {
            $item_array[$item->code] = array(
                'bill_no' => $item->bill_no,
                'bill_code' => $item->bill_code,
                'code' => $item->code,
                'couponID' => $item->couponID,
                'couponName' => $item->couponName,
                'couponType' => $item->couponType,
                'amount' => $item->amount,
                'useType' => $item->useType
            );
        }

        return $item_array;

    }

    /**
     * 查询订单使用的代金卡
     * @param int $bill_no 订单号
     * @return array|null
     */
    public function searchBillUsedCard( $bill_no ) {

        global $G_SHOP;

        if (!isset($bill_no) || empty($bill_no)) {
            return null;
        }

        $temp_item_array = &$G_SHOP->DBCA->stmt_query('SELECT * FROM bill_use_card WHERE bill_no = ?', 's', $bill_no);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();
        foreach ($temp_item_array as &$item) {

            $item_array[$item->card_no] = array(
                'bill_no' => $item->bill_no,
                'bill_code' => $item->bill_code,
                'card_no' => $item->card_no,
                'card_pwd' => decryptD($item->card_pwd),
                'card_name' => $item->card_name,
                'face_value' => $item->face_value,
                'isUse' => $item->isUse,
                'deduction' => $item->deduction
            );
        }

        return $item_array;

    }

    /**
     * 订单结算时查询订单主表信息
     * @param $arg_array
     */
    public function searchSendBill( &$arg_array ) {

        global $G_SHOP;

        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //订单流水号
        if (isset($arg_array['bill_no']) && is_numeric($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = trim($arg_array['bill_no']);
        }

        //订单号
        if (isset($arg_array['bill_code']) && is_numeric($arg_array['bill_code'])) {
            $sql .= ' AND bill_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%'.trim($arg_array['bill_code']);
        }

        //配送日期
        if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
            $sql .= ' AND send_date = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_date'];
        }

        //配送开始时间
        if (isset($arg_array['send_start_time']) && !empty($arg_array['send_start_time'])) {
            $sql .= ' AND send_start_time >= ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time'];
        }

        //配送结束时间
        if (isset($arg_array['send_start_time_end']) && !empty($arg_array['send_start_time_end'])) {
            $sql .= ' AND send_start_time <= ?  ';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time_end'];
        }

        //配送对账（是或否）
        if (isset($arg_array['is_reconciliation']) && is_numeric($arg_array['is_reconciliation'])) {
            $sql .= ' AND is_reconciliation = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['is_reconciliation'];
        }

        //财务对账（是或否）
        if (isset($arg_array['is_receivable']) && is_numeric($arg_array['is_receivable'])) {
            $sql .= ' AND is_receivable = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['is_receivable'];
        }

        //是否有应收
        if (isset($arg_array['receivable']) && is_numeric($arg_array['receivable'])) {
            if($arg_array['receivable'] == 1){
                $sql .= ' AND bill_receivable_money != "0.00" ';
            }else{
                $sql .= ' AND bill_receivable_money = "0.00" ';
            }

        }

        //城市

        $PS_LOGIN_SESSION = $G_SHOP->sessionCache_get('PS_LOGIN_SESSION');

        if (isset($arg_array['deliver_cityid']) && is_numeric($arg_array['deliver_cityid'])) {
            $sql .= ' AND deliver_cityid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_cityid'];
        }else{
            if($PS_LOGIN_SESSION['city']){
                $city  = implode(",",$PS_LOGIN_SESSION['city']);
                $sql .=" AND deliver_cityid IN ( ".$city." )";
            }
        }

        //配送站
        if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
            $sql .= ' AND distribution_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_id'];
        }

        //配送员
        if (isset($arg_array['distribution_technician_id']) && is_numeric($arg_array['distribution_technician_id'])) {
            $sql .= ' AND distribution_technician_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_technician_id'];
        }

        //是否分配配送员
        if (isset($arg_array['technician_id']) && is_numeric($arg_array['technician_id'])) {
            if($arg_array['technician_id'] == 0){
                $sql .= ' AND distribution_technician_id = ?';
                $params_type .= 'i';
                $params_array[] = $arg_array['technician_id'];
            }else if($arg_array['technician_id'] == 1){
                $sql .= ' AND distribution_technician_id != ?';
                $params_type .= 'i';
                $params_array[] = 0;
            }
        }

        //订单类型
        if(isset($arg_array['bill_type']) && !empty($arg_array['bill_type'])){
            if(strpos($arg_array['bill_type'],'all') !== false){
                $sql .= " AND billType IN (1,2,3,4,5,6,7,8,9)";
            }else{
                $sql .= " AND billType IN ( ".$arg_array['bill_type']." )";
            }
        }

        //订单状态
        if(isset($arg_array['billStatus']) && !empty($arg_array['billStatus'])){
            if(strpos($arg_array['billStatus'],'all') !== false){
                $sql .= " AND bill_status IN (5,6,7)";
            }else{
                $sql .= " AND bill_status IN ( ".$arg_array['billStatus']." )";
            }
        }else{
            $sql .= " AND bill_status IN (5,6,7)";
        }

        //发票
        if (isset($arg_array['invoice']) && is_numeric($arg_array['invoice'])) {
            $sql .= ' AND invoice = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['invoice'];
        }

        //配送单是否打印
        if (isset($arg_array['print_num']) && is_numeric($arg_array['print_num'])) {
            if($arg_array['print_num'] == 1){
                $sql .= ' AND print_num > 0';
            }else{
                $sql .= ' AND print_num = 0';
            }
        }

        //是否打印配送任务清单
        if ( isset($arg_array['printTaskList_num']) && is_numeric($arg_array['printTaskList_num']) ) {
            if($arg_array['printTaskList_num'] == 1){
                $sql .= ' AND printTaskList_num > 0';
            }else{
                $sql .= ' AND printTaskList_num = 0';
            }
        }

        //订单平台
        if (isset($arg_array['billPlatform']) && is_numeric($arg_array['billPlatform'])) {
            $sql .= ' AND billPlatform = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billPlatform'];
        }

        if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
            $sql .= $arg_array['extend'];
        }

        //add by allen.qiang 2015-02-03 FUN-AC-0037-情人节活动“约瑟芬玫瑰”不走订单结算 ---start
        $sql .= " AND bill_totalAmount <>(SELECT COUNT(*) FROM `bill_goods` WHERE bill_no=bill_master.`bill_no` AND product_code='T0399') ";
        //add by allen.qiang 2015-02-03 FUN-AC-0037-情人节活动“约瑟芬玫瑰”不走订单结算 ---start

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }

        try {

            if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                //统计数量

                $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_master' . $sql;
                $count_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
                $item_count = $count_array[0]->item_count;
                if ($item_count == 0) {
                    $arg_array['count'] = 0;
                    return null;
                }else{
                    $arg_array['count'] = $item_count;
                    //分页bug处理
                    if ($arg_array['count'] < $arg_array['rp']) {

                        $arg_array['page'] = 1;
                    }

                    //排序
                    if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                        $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                    //分页
                    if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                        $arg_array['page'] = 1;

                    $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);
                }
            } else {

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

            }

            //查询分类信息
            $search_sql = 'SELECT * FROM bill_master' . $sql;

            $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);

            if (!$temp_item_array) {
                return null;
            }

            foreach ($temp_item_array as $bill) {

                //支付状态
                switch ($bill->pay_status) {
                    case '0':
                        $bill->pay_status_name = '未付款';
                        break;
                    case 1:
                        $bill->pay_status_name ='全付';
                        break;
                    case 2:
                        $bill->pay_status_name = '部分付';
                        break;
                }

                //订单状态
                switch ($bill->bill_status) {
                    case '0':
                        if ($bill->pay_type == 1 || $bill->pay_status == 1) {
                            $bill->bill_status_name = '待审核';
                        } else {
                            $bill->bill_status_name = '待付款';
                        }
                        break;
                    case 1:
                        $bill->bill_status_name = '已确认';
                        break;
                    //mod by yim.hu 20141121 FUN-BK-0035-订单状态优化 --start    
//                     case 2:
//                         $bill->bill_status_name = '已生产';
//                         break;
//                     case 3:
//                         $bill->bill_status_name = '已入库';
//                         break;
//                     case 4:
//                         $bill->bill_status_name = '已出库';
//                         break;
//                     case 5:
//                         $bill->bill_status_name = '配送站收货';
//                         break;
//                     case 6:
//                         $bill->bill_status_name = '已配送';
//                         break;

                    case 2:
                        $bill->bill_status_name = '已打印生产单';
                        break;
                    case 3:
                        $bill->bill_status_name = '已质检入库';
                        break;
                    case 4:
                        $bill->bill_status_name = '已上车';
                        break;
                    case 5:
                        $bill->bill_status_name = '已下车';
                        break;
                    case 6:
                        $bill->bill_status_name = '已出仓';
                        break;
		    //mod by yim.hu 20141121 FUN-BK-0035-订单状态优化 --end
                    case 7:
                        $bill->bill_status_name = '已完成';
                        break;
                    case 10:
                        $bill->bill_status_name = '已取消';
                        break;
                    case 11:
                        $bill->bill_status_name = '异常订单';
                        break;
                    default:
                        $bill->bill_status_name = '';
                        break;
                }

                //配送状态
                switch ($bill->deliver_status) {
                    case '0':
                        $bill->deliver_status_name = '等待发货';
                        break;
                    case 1:
                        $bill->deliver_status_name = '部分已发货';
                        break;
                    case 2:
                        $bill->deliver_status_name = '全部已发货';
                        break;
                    case 3:
                        $bill->deliver_status_name = '已收货确认';
                        break;
                }

                //退货状态
                if( $bill->bill_withdrawAmount == $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '全部退货';
                }elseif ( $bill->bill_withdrawAmount > 0 && $bill->bill_withdrawAmount < $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '部分退货';
                }else{
                    $bill->bill_withdraw_name = '未退货';
                }

                //拒收状态
                if( $bill->bill_rejectionAmount == $bill->bill_totalAmount ){
                    $bill->bill_rejection_name = '全部拒收';
                }elseif ( $bill->bill_rejectionAmount > 0 && $bill->bill_rejectionAmount < $bill->bill_totalAmount ){
                    $bill->bill_rejection_name = '部分拒收';
                }else{
                    $bill->bill_rejection_name = '未拒收';
                }

                switch($bill->billType) {
                    case 1:
                        $bill->billTypeName = '普通订单';
                        break;
                    case 2:
                        $bill->billTypeName = '团购订单';
                        break;
                    case 3:
                        $bill->billTypeName = '秒杀订单';
                        break;
                    case 4:
                        $bill->billTypeName = '积分订单';
                        break;
                    case 5:
                        $bill->billTypeName = '补货单';
                        break;
                    case 6:
                        $bill->billTypeName = '换货单';
                        break;
                    default:
                        $bill->billTypeName = '';
                        break;
                }

                switch($bill->billPlatform) {
                    case 1:
                        $bill->billPlatformName = '自营';
                        break;
                    case 2:
                        $bill->billPlatformName = '天猫';
                        break;
                    case 3:
                        $bill->billPlatformName = '京东';
                        break;
                    case 4:
                        $bill->billPlatformName = '1号店';
                        break;
                    case 5:
                        $bill->billPlatformName = 'QQ网购';
                        break;
                    case 6:
                        $bill->billPlatformName = '凡客';
                        break;
                    case 7:
                        $bill->billPlatformName = '苏宁易购';
                        break;
                    case 8:
                        $bill->billPlatformName = '易讯';
                        break;
                    case 9:
                        $bill->billPlatformName = '拍拍';
                        break;
                    case 10:
                        $bill->billPlatformName = '亚马逊';
                        break;
                    case 11:
                        $bill->billPlatformName = '当当';
                        break;
                    case 12:
                        $bill->billPlatformName = '淘宝';
                        break;
                    case 13:
                        $bill->billPlatformName = '实体店';
                        break;
                    default:
                        $bill->billTypeName = '';
                        break;
                }

                switch($bill->billChannel) {
                    case 1:
                        $bill->billChannelName = 'web';
                        break;
                    case 2:
                        $bill->billChannelName = 'wap';
                        break;
                    case 3:
                        $bill->billChannelName = '微信';
                        break;
                    case 4:
                        $bill->billChannelName = 'app';
                        break;
                    case 5:
                        $bill->billChannelName = '线下';
                        break;
                    case 6:
                        $bill->billChannelName = '客服';
                        break;
                    default:
                        $bill->billChannelName = '';
                        break;
                }

                $item_array[] = array(
                    //订单信息
                    'bill_no' => (string)$bill->bill_no,
                    'uuid' => $bill->uuid,
                    'timeStamp' => $bill->timeStamp,
                    'creator' => $bill->creator,
                    'createTime' => $bill->createTime,
                    'bill_code' =>(string) $bill->bill_code,
                    'pcustID' => $bill->pcustID,
                    'custID' => $bill->custID,
                    'bill_status' => $bill->bill_status,
                    'billPlatform' => $bill->billPlatform,
                    'billPlatformName' => $bill->billPlatformName,
                    'billChannel' => $bill->billChannel,
                    'billChannelName' => $bill->billChannelName,
                    'billType' => $bill->billType,
                    'billTypeName' => $bill->billTypeName,
                    'bill_status_name' => $bill->bill_status_name,
                    'bill_cancel' => $bill->bill_cancel,
                    'bill_cancelTime' => $bill->bill_cancelTime,
                    'bill_totalMoney' => $bill->bill_totalMoney,
                    'bill_money' => $bill->bill_money,
                    'bill_received_money' => $bill->bill_received_money,
                    'bill_receivable_money' => $bill->bill_receivable_money,
                    'bill_totalPaid' => $bill->bill_totalPaid,
                    'bill_totalPoints' => $bill->bill_totalPoints,
                    'bill_pointsPrice' => $bill->bill_pointsPrice,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'bill_withdraw_name' => $bill->bill_withdraw_name,
                    'bill_rejection_name' => $bill->bill_rejection_name,
                    'bill_subtract_money' => $bill->bill_subtract_money,
                    'bill_coupon_money' => $bill->bill_coupon_money,
                    'bill_accessories_money' => $bill->bill_accessories_money,
                    'bill_card_money' => $bill->bill_card_money,
                    'bill_points_money' => $bill->bill_points_money,
                    'bill_balance_money' => $bill->bill_balance_money,
                    'bill_online_money' => $bill->bill_online_money,
                    'is_urgent' => $bill->is_urgent,
                    'is_reconciliation' => $bill->is_reconciliation,
                    'is_receivable' => $bill->is_receivable,
                    'pay_id_str' =>$bill->pay_id_str,
                    'pay_name_str' =>$bill->pay_name_str,
                    'bill_reject_cause' =>$bill->bill_reject_cause,

                    //收货人信息
                    'deliverid' => $bill->deliverid,
                    'deliver_name' => decryptD($bill->deliver_name),
                    'deliver_province' => $bill->deliver_province,
                    'deliver_provinceid' => $bill->deliver_provinceid,
                    'deliver_city' => $bill->deliver_city,
                    'deliver_cityid' => $bill->deliver_cityid,
                    'deliver_county' => $bill->deliver_county,
                    'deliver_countyid' => $bill->deliver_countyid,
                    'deliver_address' => decryptD($bill->deliver_address),
                    'deliver_all_address' => $bill->deliver_province . $bill->deliver_city . $bill->deliver_county . decryptD($bill->deliver_address),
                    'deliver_postalCode' => $bill->deliver_postalCode,
                    'deliver_mobile' => decryptD($bill->deliver_mobile),
                    'deliver_phone' => decryptD($bill->deliver_phone),

                    //配送
                    'distribution_id' => $bill->distribution_id,//配送站ID
                    'distribution_name' => $bill->distribution_name,//配送站名称
                    'distribution_technician_id' => $bill->distribution_technician_id,//配送站ID
                    'distribution_technicia' => $bill->distribution_technicia,//配送站名称
                    'sendTypeID' => $bill->sendTypeID, //配送方式ID
                    'sendTypeName' => $bill->sendTypeName, //配送方式名称
                    'send_region_name' => $bill->send_region_name, //配送区域名称
                    'send_region_id' => $bill->send_region_id, //配送区域ID
                    'deliver_fee' => $bill->deliver_fee, //应收运费
                    'deliver_feePaid' => $bill->deliver_feePaid, //实收运费
                    'deliver_status' => $bill->deliver_status, //配送状态
                    'deliver_status_name' => $bill->deliver_status_name, //配送状态
                    'deliver_time' => $bill->deliver_time, //配送状态变化时间
                    'send_date' => $bill->send_date,
                    'send_start_time' => $bill->send_start_time,
                    'send_end_time' => $bill->send_end_time,

                    //付款
                    'pay_status' => $bill->pay_status, //付款状态
                    'pay_status_name' => $bill->pay_status_name, //付款方式名称
                    'payed_time' => $bill->payed_time, //付款时间
                    'pay_type' => $bill->pay_type, //支付方式类型
                    'payTypeID' => $bill->payTypeID, //支付方式ID
                    'payTypeName' => $bill->payTypeName, //支付方式名称

                    //发票信息
                    'invoice' => $bill->invoice,
                    'invoiceID' => $bill->invoiceID,
                    'invoice_type' => $bill->invoice_type,
                    'invoice_title_type' => $bill->invoice_title_type,
                    'invoice_title' => $bill->invoice_title,
                    'invoice_content_id' => $bill->invoice_content_id,
                    'invoice_content' => $bill->invoice_content,
                    'invoice_amount' => $bill->invoice_amount,
                    'invoice_number' => $bill->invoice_number,

                    'remark' => $bill->remark,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'external_bill_no' => $bill->external_bill_no

                );
            }

            return $item_array;

        } catch (Exception $e) {

            error_log($e->getMessage());
            return null;
        }


    }

    /**
     * 查询订单商品的配件信息
     * @param $arg_array
     * @return array|null
     */
    public function searchGoodsFittingsBill( &$arg_array ) {

        if (!isset($arg_array['bill_goods_no']) || empty($arg_array['bill_goods_no'])) {
            return null;
        }

        global $G_SHOP;

        //查询分类信息
        $search_sql = 'SELECT * FROM bill_goods_fittings WHERE bill_goods_no = ?';
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, 's', $arg_array['bill_goods_no']);

        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();

        foreach ($temp_item_array as $bill) {

            switch($bill->fitUnit){
                case 1:
                    $bill->fitUnit_name = '套';
                    break;
                case 2:
                    $bill->fitUnit_name = '份';
                    break;
                case 3:
                    $bill->fitUnit_name = '个';
                    break;
                case 4:
                    $bill->fitUnit_name = '包';
                    break;
                default :
                    $bill->fitUnit_name = '';
                    break;
            }

            $item_array[$bill->fitID] = array(
                'bill_no' => $bill->bill_no,
                'uuid' => $bill->uuid,
                'timeStamp' => $bill->timeStamp,
                'creator' => $bill->creator,
                'createTime' => $bill->createTime,
                'bill_code' => $bill->bill_code,
                'fitID' => $bill->fitID,
                'fitName' => $bill->fitName,
                'buyNum' => $bill->buyNum,
                'quantity' => $bill->quantity,
                'price' => $bill->price,
                'fitUnit' => $bill->fitUnit,
                'fitUnit_name' => $bill->fitUnit_name,
                'buyMoney' => $bill->buyMoney,

            );
        }

        return $item_array;


    }

    /**
     * 查询订单所有额外配件信息
     * add by allen.qiang 20160421 用于打印配送单使用
     * @param $arg_array
     * @return array|null
     */
    public function searchFittingsBill( $bill_no ) {

        if (!isset($bill_no) || empty($bill_no)) {
            return null;
        }

        global $G_SHOP;

        //查询分类信息
        $search_sql = 'SELECT * FROM bill_goods_fittings WHERE bill_no = ? AND buyMoney > 0';
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, 's', $bill_no);

        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();

        foreach ($temp_item_array as $bill) {

            switch($bill->fitUnit){
                case 1:
                    $bill->fitUnit_name = '套';
                    break;
                case 2:
                    $bill->fitUnit_name = '份';
                    break;
                case 3:
                    $bill->fitUnit_name = '个';
                    break;
                case 4:
                    $bill->fitUnit_name = '包';
                    break;
                default :
                    $bill->fitUnit_name = '';
                    break;
            }

            $item_array[$bill->fitID] = array(
                'bill_no' => $bill->bill_no,
                'uuid' => $bill->uuid,
                'timeStamp' => $bill->timeStamp,
                'creator' => $bill->creator,
                'createTime' => $bill->createTime,
                'bill_code' => $bill->bill_code,
                'fitID' => $bill->fitID,
                'fitName' => $bill->fitName,
                'buyNum' => $bill->buyNum,
                'quantity' => $bill->quantity,
                'price' => $bill->price,
                'fitUnit' => $bill->fitUnit,
                'fitUnit_name' => $bill->fitUnit_name,
                'buyMoney' => $bill->buyMoney,

            );
        }

        return $item_array;


    }

    /**
     * 查询订单配送对账信息
     * @param array $arg_array
     * @return null|array
     */
    public function searchBillPayMoney( &$arg_array ) {

        global $G_SHOP;

        //sql字符串
        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //订单号
        if (isset($arg_array['bill_no']) && is_numeric($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_no'];
        }

        //支付方式ID
        if (isset($arg_array['payTypeID']) && is_numeric($arg_array['payTypeID'])) {
            $sql .= ' AND payTypeID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['payTypeID'];
        }

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }


        try {

            if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                //统计数量
                $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_distribution_checking ' . $sql;
                $count_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
                $item_count = $count_array[0]->item_count;
                if ($item_count == 0) {
                    $arg_array['count'] = 0;
                    return null;
                }

                $arg_array['count'] = $item_count;

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                //分页
                if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                    $arg_array['page'] = 1;

                $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);

            } else {

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

            }

            //查询分类信息
            $search_sql = 'SELECT * FROM bill_distribution_checking ' . $sql;
            $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);

            if (!$temp_item_array) {
                return null;
            }

            foreach ($temp_item_array as &$item) {
                $item_array[] = array(
                    'bill_no' => $item->bill_no,
                    'bill_pay_no' => $item->bill_pay_no,
                    'payTypeID' => $item->payTypeID,
                    'payTypeName' => $item->payTypeName,
                    'type' => $item->type,
                    'pay_amount' => $item->pay_amount,
                    'deduct_amount' => $item->deduct_amount,
                    'pay_code' => $item->pay_code,
                    'pay_time' => $item->pay_time,
                    'payment_method_id' => $item->payment_method_id,
                    'payment_method_name' => $item->payment_method_name,
                    'payment_method_type' => $item->payment_method_type,
                    'receipt_amount' => $item->receipt_amount,
                );
            }

            return $item_array;

        } catch (Exception $e) {

            error_log($e->getMessage());
            return null;
        }

    }

    /**
     * 查询代付订单信息
     * @param $arg_array
     * @return array|null
     */
    public function searchBillPayingAgent( $arg_array ) {

        global $G_SHOP;

        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //从订单号
        if (isset($arg_array['bill_no']) && is_numeric($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_no'];
        }

        //从订单编号
        if (isset($arg_array['bill_code']) && is_numeric($arg_array['bill_code'])) {
            $sql .= ' AND bill_code = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_code'];
        }

        //主订单号
        if (isset($arg_array['main_bill_no']) && is_numeric($arg_array['main_bill_no'])) {
            $sql .= ' AND main_bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['main_bill_no'];
        }

        if (empty($sql)) {
            return null;
        }

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }

        //查询分类信息
        $search_sql = 'SELECT * FROM bill_paying_agent' . $sql;
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();

        foreach ($temp_item_array as $bill) {

            $item_array[$bill->bill_code] = array(
                'createTime' => $bill->createTime,
                'main_bill_no' => $bill->main_bill_no,
                'bill_no' => $bill->bill_no,
                'bill_code' => $bill->bill_code,
                'deliver_name' => $bill->deliver_name,
                'bill_receivable_money' => $bill->bill_receivable_money
            );
        }

        return $item_array;

    }


    /**
     * 订单分配，生产查询时查询订单主表信息
     * @param $arg_array
     */
    public function searchQueryBill( &$arg_array ) {

        global $G_SHOP;

        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //下单日期
        if (isset($arg_array['createDate']) && !empty($arg_array['createDate'])) {

            $sql .= ' AND createTime >= ? AND createTime<= ? ';
            $params_type .= 'ss';
            $params_array[] = $arg_array['createDate'].' '.'00:00:00';
            $params_array[] = $arg_array['createDate'].' '.'23:59:59';
        }

        //订单流水号
        if (isset($arg_array['bill_no']) && is_numeric($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_no'];
        }

        //订单号
        if (isset($arg_array['bill_code']) && is_numeric($arg_array['bill_code'])) {
            $sql .= ' AND bill_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%'.$arg_array['bill_code'];
        }

        //配送日期
        if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
            $sql .= ' AND send_date = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_date'];
        }

        //配送开始时间
        if (isset($arg_array['send_start_time']) && !empty($arg_array['send_start_time'])) {
            $sql .= ' AND send_start_time >= ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time'];
        }

        //配送结束时间
        if (isset($arg_array['send_start_time_end']) && !empty($arg_array['send_start_time_end'])) {
            $sql .= ' AND send_start_time <= ?  ';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time_end'];
        }

        //配送对账（是或否）
        if (isset($arg_array['is_reconciliation']) && is_numeric($arg_array['is_reconciliation'])) {
            $sql .= ' AND is_reconciliation = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['is_reconciliation'];
        }

        //财务对账（是或否）
        if (isset($arg_array['is_receivable']) && is_numeric($arg_array['is_receivable'])) {
            $sql .= ' AND is_receivable = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['is_receivable'];
        }

        //是否有应收
        if (isset($arg_array['receivable']) && is_numeric($arg_array['receivable'])) {
            if($arg_array['receivable'] == 1){
                $sql .= ' AND bill_receivable_money > 0';
            }else{
                $sql .= ' AND bill_receivable_money = "0.00" ';
            }

        }

        //城市
        $PS_LOGIN_SESSION = $G_SHOP->sessionCache_get('PS_LOGIN_SESSION');

        if (isset($arg_array['deliver_cityid']) && is_numeric($arg_array['deliver_cityid'])) {
            $sql .= ' AND deliver_cityid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_cityid'];
        }else{
            if($PS_LOGIN_SESSION['city']){
                $city  = implode(",",$PS_LOGIN_SESSION['city']);
                $sql .=" AND deliver_cityid IN ( ".$city." )";
            }
        }

        //配送站
        if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
            $sql .= ' AND distribution_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_id'];
        }

        //配送员
        if (isset($arg_array['distribution_technician_id']) && is_numeric($arg_array['distribution_technician_id'])) {
            $sql .= ' AND distribution_technician_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_technician_id'];
        }

        //是否分配配送员
        if (isset($arg_array['technician_id']) && is_numeric($arg_array['technician_id'])) {
            if($arg_array['technician_id'] == 0){
                $sql .= ' AND distribution_technician_id = ?';
                $params_type .= 'i';
                $params_array[] = $arg_array['technician_id'];
            }else if($arg_array['technician_id'] == 1){
                $sql .= ' AND distribution_technician_id != ?';
                $params_type .= 'i';
                $params_array[] = 0;
            }
        }

        //订单类型
        if(isset($arg_array['bill_type']) && !empty($arg_array['bill_type'])){
            if(strpos($arg_array['bill_type'],'all') !== false){
                $sql .= " AND billType IN (1,2,3,4,5,6,7,8,9)";
            }else{
                $sql .= " AND billType IN ( ".$arg_array['bill_type']." )";
            }
        }


        
        //订单状态
        if(isset($arg_array['billStatus']) && !empty($arg_array['billStatus'])){
            if(strpos($arg_array['billStatus'],'all') !== false){
                $sql .= " AND bill_status IN (1,2,3,4,5,6)";
            }else{
                $sql .= " AND bill_status IN ( ".$arg_array['billStatus']." )";
            }
        }else{
            $sql .= " AND bill_status IN (1,2,3,4,5,6)";
        }

        //订单平台
        if (isset($arg_array['billPlatform']) && is_numeric($arg_array['billPlatform'])) {
            $sql .= ' AND billPlatform = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billPlatform'];
        }


        //发票
        if (isset($arg_array['invoice']) && is_numeric($arg_array['invoice'])) {
            $sql .= ' AND invoice = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['invoice'];
        }

        //配送单是否打印
        if (isset($arg_array['print_num']) && is_numeric($arg_array['print_num'])) {
            if($arg_array['print_num'] == 1){
                $sql .= ' AND print_num > 0';
            }else{
                $sql .= ' AND print_num = 0';
            }
        }

        //是否打印配送任务清单
        if ( isset($arg_array['printTaskList_num']) && is_numeric($arg_array['printTaskList_num']) ) {
            if($arg_array['printTaskList_num'] == 1){
                $sql .= ' AND printTaskList_num > 0';
            }else{
                $sql .= ' AND printTaskList_num = 0';
            }
        }

        if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
            $sql .= $arg_array['extend'];
        }

        //add by allen.qiang 2015-02-03 FUN-AC-0037-情人节活动“约瑟芬玫瑰”不走订单打印、订单分配 ---start
        $sql .= " AND bill_totalAmount <>(SELECT COUNT(*) FROM `bill_goods` WHERE bill_no=bill_master.`bill_no` AND product_code='T0399') ";
        //add by allen.qiang 2015-02-03 FUN-AC-0037-情人节活动“约瑟芬玫瑰”不走订单打印、订单分配 ---start

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }


        try {

            if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                //统计数量

                $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_master' . $sql;
                $count_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
                $item_count = $count_array[0]->item_count;
                if ($item_count == 0) {
                    $arg_array['count'] = 0;
                    return null;
                }else{
                    $arg_array['count'] = $item_count;
                    //分页bug处理
                    if ($arg_array['count'] < $arg_array['rp']) {

                        $arg_array['page'] = 1;
                    }

                    //排序
                    if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                        $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                    //分页
                    if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                        $arg_array['page'] = 1;

                    $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);
                }
            } else {

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

            }

            //查询分类信息
            $search_sql = 'SELECT * FROM bill_master' . $sql;

            $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);

            if (!$temp_item_array) {
                return null;
            }

            foreach ($temp_item_array as $bill) {

                $arg = array(
                    'bill_no'=>$bill->bill_no
                );
                //查询订单商品磅数
                $bill_goods_array = $this->searchBillGoods( $arg );

                $goods_spec_array = array(); //商品规格数组
                if( $bill_goods_array ){
                    foreach( $bill_goods_array as $v ){
                        $goods_spec_array[] = $v['goods_spec'];
                    }
                }

                $goods_spec_str = implode(',',$goods_spec_array);
                //支付状态
                switch ($bill->pay_status) {
                    case '0':
                        $bill->pay_status_name = '未付款';
                        break;
                    case 1:
                        $bill->pay_status_name ='全付';
                        break;
                    case 2:
                        $bill->pay_status_name = '部分付';
                        break;
                }

                //订单状态
                switch ($bill->bill_status) {
                    case '0':
                        if ($bill->pay_type == 1 || $bill->pay_status == 1) {
                            $bill->bill_status_name = '待审核';
                        } else {
                            $bill->bill_status_name = '待付款';
                        }
                        break;
                    case 1:
                        $bill->bill_status_name = '已确认';
                        break;
                    //mod by yim.hu 20141121 FUN-BK-0035-订单状态优化 --start    
//                     case 2:
//                         $bill->bill_status_name = '已生产';
//                         break;
//                     case 3:
//                         $bill->bill_status_name = '已入库';
//                         break;
//                     case 4:
//                         $bill->bill_status_name = '已出库';
//                         break;
//                     case 5:
//                         $bill->bill_status_name = '配送站收货';
//                         break;
//                     case 6:
//                         $bill->bill_status_name = '已配送';
//                         break;

                    case 2:
                        $bill->bill_status_name = '已打印生产单';
                        break;
                    case 3:
                        $bill->bill_status_name = '已质检入库';
                        break;
                    case 4:
                        $bill->bill_status_name = '已上车';
                        break;
                    case 5:
                        $bill->bill_status_name = '已下车';
                        break;
                    case 6:
                        $bill->bill_status_name = '已出仓';
                        break;
                    //mod by yim.hu 20141121 FUN-BK-0035-订单状态优化 --end
                    case 7:
                        $bill->bill_status_name = '已完成';
                        break;
                    case 10:
                        $bill->bill_status_name = '已取消';
                        break;
                    case 11:
                        $bill->bill_status_name = '异常订单';
                        break;
                    default:
                        $bill->bill_status_name = '';
                        break;
                }

                //配送状态
                switch ($bill->deliver_status) {
                    case '0':
                        $bill->deliver_status_name = '等待发货';
                        break;
                    case 1:
                        $bill->deliver_status_name = '部分已发货';
                        break;
                    case 2:
                        $bill->deliver_status_name = '全部已发货';
                        break;
                    case 3:
                        $bill->deliver_status_name = '已收货确认';
                        break;
                }

                //退货状态
                if( $bill->bill_withdrawAmount == $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '全部退货';
                }elseif ( $bill->bill_withdrawAmount > 0 && $bill->bill_withdrawAmount < $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '部分退货';
                }else{
                    $bill->bill_withdraw_name = '未退货';
                }

                //拒收状态
                if( $bill->bill_rejectionAmount == $bill->bill_totalAmount ){
                    $bill->bill_rejection_name = '全部拒收';
                }elseif ( $bill->bill_rejectionAmount > 0 && $bill->bill_rejectionAmount < $bill->bill_totalAmount ){
                    $bill->bill_rejection_name = '部分拒收';
                }else{
                    $bill->bill_rejection_name = '未拒收';
                }

                switch($bill->billType) {
                    case 1:
                        $bill->billTypeName = '普通订单';
                        break;
                    case 2:
                        $bill->billTypeName = '团购订单';
                        break;
                    case 3:
                        $bill->billTypeName = '秒杀订单';
                        break;
                    case 4:
                        $bill->billTypeName = '积分订单';
                        break;
                    case 5:
                        $bill->billTypeName = '补货单';
                        break;
                    case 6:
                        $bill->billTypeName = '换货单';
                        break;
                    default:
                        $bill->billTypeName = '';
                        break;
                }

                switch($bill->billPlatform) {
                    case 1:
                        $bill->billPlatformName = '自营';
                        break;
                    case 2:
                        $bill->billPlatformName = '天猫';
                        break;
                    case 3:
                        $bill->billPlatformName = '京东';
                        break;
                    case 4:
                        $bill->billPlatformName = '1号店';
                        break;
                    case 5:
                        $bill->billPlatformName = 'QQ网购';
                        break;
                    case 6:
                        $bill->billPlatformName = '凡客';
                        break;
                    case 7:
                        $bill->billPlatformName = '苏宁易购';
                        break;
                    case 8:
                        $bill->billPlatformName = '易讯';
                        break;
                    case 9:
                        $bill->billPlatformName = '拍拍';
                        break;
                    case 10:
                        $bill->billPlatformName = '亚马逊';
                        break;
                    case 11:
                        $bill->billPlatformName = '当当';
                        break;
                    case 12:
                        $bill->billPlatformName = '淘宝';
                        break;
                    case 13:
                        $bill->billPlatformName = '实体店';
                        break;
                    default:
                        $bill->billTypeName = '';
                        break;
                }

                switch($bill->billChannel) {
                    case 1:
                        $bill->billChannelName = 'web';
                        break;
                    case 2:
                        $bill->billChannelName = 'wap';
                        break;
                    case 3:
                        $bill->billChannelName = '微信';
                        break;
                    case 4:
                        $bill->billChannelName = 'app';
                        break;
                    case 5:
                        $bill->billChannelName = '线下';
                        break;
                    case 6:
                        $bill->billChannelName = '客服';
                        break;
                    default:
                        $bill->billChannelName = '';
                        break;
                }

                $item_array[] = array(
                    //订单信息
                    'bill_no' => (string)$bill->bill_no,
                    'uuid' => $bill->uuid,
                    'timeStamp' => $bill->timeStamp,
                    'creator' => $bill->creator,
                    'createTime' => $bill->createTime,
                    'bill_code' =>(string) $bill->bill_code,
                    'pcustID' => $bill->pcustID,
                    'custID' => $bill->custID,
                    'bill_status' => $bill->bill_status,
                    'billPlatform' => $bill->billPlatform,
                    'billPlatformName' => $bill->billPlatformName,
                    'billChannel' => $bill->billChannel,
                    'billChannelName' => $bill->billChannelName,
                    'billType' => $bill->billType,
                    'billTypeName' => $bill->billTypeName,
                    'bill_status_name' => $bill->bill_status_name,
                    'bill_cancel' => $bill->bill_cancel,
                    'bill_cancelTime' => $bill->bill_cancelTime,
                    'bill_totalMoney' => $bill->bill_totalMoney,
                    'bill_totalPaid' => $bill->bill_totalPaid,
                    'bill_totalPoints' => $bill->bill_totalPoints,
                    'bill_pointsPrice' => $bill->bill_pointsPrice,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'bill_withdraw_name' => $bill->bill_withdraw_name,
                    'bill_rejection_name' => $bill->bill_rejection_name,
                    'bill_subtract_money' => $bill->bill_subtract_money,
                    'bill_coupon_money' => $bill->bill_coupon_money,
                    'bill_accessories_money' => $bill->bill_accessories_money,
                    'bill_card_money' => $bill->bill_card_money,
                    'bill_points_money' => $bill->bill_points_money,
                    'bill_money'=>$bill->bill_money,
                    'bill_receivable_money' => $bill->bill_receivable_money,
                    'is_urgent' => $bill->is_urgent,
                    'is_reconciliation' => $bill->is_reconciliation,
                    'is_receivable' => $bill->is_receivable,

                    //收货人信息
                    'deliverid' => $bill->deliverid,
                    'deliver_name' => decryptD($bill->deliver_name),
                    'deliver_province' => $bill->deliver_province,
                    'deliver_provinceid' => $bill->deliver_provinceid,
                    'deliver_city' => $bill->deliver_city,
                    'deliver_cityid' => $bill->deliver_cityid,
                    'deliver_county' => $bill->deliver_county,
                    'deliver_countyid' => $bill->deliver_countyid,
                    'deliver_address' => decryptD($bill->deliver_address),
                    'deliver_all_address' => $bill->deliver_province . $bill->deliver_city . $bill->deliver_county . decryptD($bill->deliver_address),
                    'deliver_postalCode' => $bill->deliver_postalCode,
                    'deliver_mobile' => decryptD($bill->deliver_mobile),
                    'deliver_phone' => decryptD($bill->deliver_phone),

                    //配送
                    'distribution_id' => $bill->distribution_id,//配送站ID
                    'distribution_name' => $bill->distribution_name,//配送站名称
                    'distribution_technician_id' => $bill->distribution_technician_id,//配送站ID
                    'distribution_technicia' => $bill->distribution_technicia,//配送站名称
                    'sendTypeID' => $bill->sendTypeID, //配送方式ID
                    'sendTypeName' => $bill->sendTypeName, //配送方式名称
                    'send_region_name' => $bill->send_region_name, //配送区域名称
                    'send_region_id' => $bill->send_region_id, //配送区域ID
                    'deliver_fee' => $bill->deliver_fee, //应收运费
                    'deliver_feePaid' => $bill->deliver_feePaid, //实收运费
                    'deliver_status' => $bill->deliver_status, //配送状态
                    'deliver_status_name' => $bill->deliver_status_name, //配送状态
                    'deliver_time' => $bill->deliver_time, //配送状态变化时间
                    'send_date' => $bill->send_date,
                    'send_start_time' => $bill->send_start_time,
                    'send_end_time' => $bill->send_end_time,

                    //付款
                    'pay_status' => $bill->pay_status, //付款状态
                    'pay_status_name' => $bill->pay_status_name, //付款方式名称
                    'payed_time' => $bill->payed_time, //付款时间
                    'pay_type' => $bill->pay_type, //支付方式类型
                    'payTypeID' => $bill->payTypeID, //支付方式ID
                    'payment_method_id'=>$bill->payment_method_id,//
                    'payTypeName' => $bill->payTypeName, //支付方式名称
                    'payment_method_name'=>$bill->payment_method_name,//付款方式
                    //发票信息
                    'invoice' => $bill->invoice,
                    'invoiceID' => $bill->invoiceID,
                    'invoice_type' => $bill->invoice_type,
                    'invoice_title_type' => $bill->invoice_title_type,
                    'invoice_title' => $bill->invoice_title,
                    'invoice_content_id' => $bill->invoice_content_id,
                    'invoice_content' => $bill->invoice_content,
                    'invoice_amount' => $bill->invoice_amount,
                    'invoice_number' => $bill->invoice_number,

                    'print_num' => $bill->print_num,
                    'print_time'=> $bill->print_time,
                    'remark' => $bill->remark,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'external_bill_no' => $bill->external_bill_no,
                    'printTaskList_num'=>$bill->printTaskList_num,
                    'special_status'=>$bill->special_status,
                    'billPromotion'=>$bill->billPromotion,//促销渠道
                    'paying_agent_str'=>$bill->paying_agent_str,//代付订单
                    'goods_spec_str'=>$goods_spec_str,
                    //mod by allen.qiang 20141106 FUN-BK-0025-Mcake配送单打印优化 start
                    'special_status'=>$bill->special_status
                    //mod by allen.qiang 20141106 FUN-BK-0025-Mcake配送单打印优化 end
                );
            }

            return $item_array;

        } catch (Exception $e) {

            error_log($e->getMessage());
            return null;
        }


    }

    /**
     * 查询异地付款
     * @param array $arg_array
     * @return null|array
     */
    public function searchBillOtherAddressPay( $arg_array ) {

        if (!isset($arg_array['bill_no']) || empty($arg_array['bill_no'])) {
            return null;
        }

        global $G_SHOP;

        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //从订单号
        if (isset($arg_array['bill_no']) && is_numeric($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_no'];
        }

        if (empty($sql)) {
            return null;
        }

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }

        //查询分类信息
        $search_sql = 'SELECT * FROM bill_other_address_pay' . $sql;
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
        if (!$temp_item_array) {
            return null;
        }
        $item_array = array();

        foreach ($temp_item_array as $bill) {
            $item_array[] = array(
                'createTime' => $bill->createTime,
                'bill_no' => $bill->bill_no,
                'bill_code' => $bill->bill_code,
                'custName' => $bill->custName,
                'mobile' => $bill->mobile,
                'address' => $bill->address,
                'date' => $bill->date,
                'startTime' => $bill->startTime,
                'endTime' => $bill->endTime
            );
        }

        return $item_array;
    }


    /**
     * 调度星盘查询订单主表信息
     * @param $arg_array
     */
    public function searchBillMaster( &$arg_array ) {

        global $G_SHOP;

        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //下单日期
        if (isset($arg_array['createDate']) && !empty($arg_array['createDate'])) {

            $sql .= ' AND createTime >= ? AND createTime<= ? ';
            $params_type .= 'ss';
            $params_array[] = $arg_array['createDate'].' '.'00:00:00';
            $params_array[] = $arg_array['createDate'].' '.'23:59:59';
        }

        //订单流水号
        if (isset($arg_array['bill_no']) && is_numeric($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['bill_no'];
        }

        //订单号
        if (isset($arg_array['bill_code']) && is_numeric($arg_array['bill_code'])) {
            $sql .= ' AND bill_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%'.$arg_array['bill_code'];
        }

        //配送日期
        if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
            $sql .= ' AND send_date = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_date'];
        }

        //配送开始时间
        if (isset($arg_array['send_start_time']) && !empty($arg_array['send_start_time'])) {
            $sql .= ' AND send_start_time >= ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time'];
        }

        //配送结束时间
        if (isset($arg_array['send_start_time_end']) && !empty($arg_array['send_start_time_end'])) {
            $sql .= ' AND send_start_time <= ?  ';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time_end'];
        }


        //城市
        $PS_LOGIN_SESSION = $G_SHOP->sessionCache_get('PS_LOGIN_SESSION');

        if (isset($arg_array['deliver_cityid']) && is_numeric($arg_array['deliver_cityid'])) {
            $sql .= ' AND deliver_cityid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_cityid'];
        }else{
            if($PS_LOGIN_SESSION['city']){
                $city  = implode(",",$PS_LOGIN_SESSION['city']);
                $sql .=" AND deliver_cityid IN ( ".$city." )";
            }
        }

        //配送站
        if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
            $sql .= ' AND distribution_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_id'];
        }

        //配送员
        if (isset($arg_array['distribution_technician_id']) && is_numeric($arg_array['distribution_technician_id'])) {
            $sql .= ' AND distribution_technician_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_technician_id'];
        }

        //是否分配配送员
        if (isset($arg_array['technician_id']) && is_numeric($arg_array['technician_id'])) {
            if($arg_array['technician_id'] == 0){
                $sql .= ' AND distribution_technician_id = ?';
                $params_type .= 'i';
                $params_array[] = $arg_array['technician_id'];
            }else if($arg_array['technician_id'] == 1){
                $sql .= ' AND distribution_technician_id != ?';
                $params_type .= 'i';
                $params_array[] = 0;
            }
        }

        //订单类型
        if(isset($arg_array['bill_type']) && !empty($arg_array['bill_type'])){
            if(strpos($arg_array['bill_type'],'all') !== false){
                $sql .= " AND billType IN (1,2,3,4,5,6,7,8,9)";
            }else{
                $sql .= " AND billType IN ( ".$arg_array['bill_type']." )";
            }
        }



        //订单状态
        if(isset($arg_array['billStatus']) && !empty($arg_array['billStatus'])){
            if(strpos($arg_array['billStatus'],'all') !== false){
                $sql .= " AND bill_status IN (1,2,3,4,5,6,7)";
            }else{
                $sql .= " AND bill_status IN ( ".$arg_array['billStatus']." )";
            }
        }else{
            $sql .= " AND bill_status IN (1,2,3,4,5,6,7)";
        }

        //发票
        if (isset($arg_array['invoice']) && is_numeric($arg_array['invoice'])) {
            $sql .= ' AND invoice = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['invoice'];
        }

        //配送单是否打印
        if (isset($arg_array['print_num']) && is_numeric($arg_array['print_num'])) {
            if($arg_array['print_num'] == 1){
                $sql .= ' AND print_num > 0';
            }else{
                $sql .= ' AND print_num = 0';
            }
        }

        //是否打印配送任务清单
        if ( isset($arg_array['printTaskList_num']) && is_numeric($arg_array['printTaskList_num']) ) {
            if($arg_array['printTaskList_num'] == 1){
                $sql .= ' AND printTaskList_num > 0';
            }else{
                $sql .= ' AND printTaskList_num = 0';
            }
        }

        if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
            $sql .= $arg_array['extend'];
        }

        //add by allen.qiang 2015-02-03 FUN-AC-0037-情人节活动“约瑟芬玫瑰”不走调度星盘 ---start
        $sql .= " AND bill_totalAmount <>(SELECT COUNT(*) FROM `bill_goods` WHERE bill_no=bill_master.`bill_no` AND product_code='T0399') ";
        //add by allen.qiang 2015-02-03 FUN-AC-0037-情人节活动“约瑟芬玫瑰”不走调度星盘 ---start

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }


        try {

            if (isset($arg_array['rp']) && $arg_array['rp'] > 0) {

                //统计数量

                $search_sql = 'SELECT COUNT(*) AS item_count FROM bill_master' . $sql;
                $count_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
                $item_count = $count_array[0]->item_count;
                if ($item_count == 0) {
                    $arg_array['count'] = 0;
                    return null;
                }else{
                    $arg_array['count'] = $item_count;
                    //分页bug处理
                    if ($arg_array['count'] < $arg_array['rp']) {

                        $arg_array['page'] = 1;
                    }

                    //排序
                    if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                        $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

                    //分页
                    if (!isset($arg_array['page']) || !is_numeric($arg_array['page']) || $arg_array['page'] <= 0)
                        $arg_array['page'] = 1;

                    $sql .= sprintf(' LIMIT %d, %d', ($arg_array['page'] - 1) * $arg_array['rp'], $arg_array['rp']);
                }
            } else {

                //排序
                if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
                    $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);

            }

            //查询分类信息
            $search_sql = 'SELECT * FROM bill_master' . $sql;

            $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);

            if (!$temp_item_array) {
                return null;
            }

            foreach ($temp_item_array as $bill) {

                $arg = array(
                    'bill_no'=>$bill->bill_no
                );
                //查询订单商品磅数
                $bill_goods_array = $this->searchBillGoods( $arg );

                $goods_spec_array = array(); //商品规格数组
                if( $bill_goods_array ){
                    foreach( $bill_goods_array as $v ){
                        $goods_spec_array[] = $v['goods_spec'];
                    }
                }

                $goods_spec_str = implode(',',$goods_spec_array);
                //支付状态
                switch ($bill->pay_status) {
                    case '0':
                        $bill->pay_status_name = '未付款';
                        break;
                    case 1:
                        $bill->pay_status_name ='全付';
                        break;
                    case 2:
                        $bill->pay_status_name = '部分付';
                        break;
                }

                //订单状态
                switch ($bill->bill_status) {
                    case '0':
                        if ($bill->pay_type == 1 || $bill->pay_status == 1) {
                            $bill->bill_status_name = '待审核';
                        } else {
                            $bill->bill_status_name = '待付款';
                        }
                        break;
                    case 1:
                        $bill->bill_status_name = '已确认';
                        break;
                    //mod by yim.hu 20141121 FUN-BK-0035-订单状态优化 --start    
//                     case 2:
//                         $bill->bill_status_name = '已生产';
//                         break;
//                     case 3:
//                         $bill->bill_status_name = '已入库';
//                         break;
//                     case 4:
//                         $bill->bill_status_name = '已出库';
//                         break;
//                     case 5:
//                         $bill->bill_status_name = '配送站收货';
//                         break;
//                     case 6:
//                         $bill->bill_status_name = '已配送';
//                         break;

                    case 2:
                        $bill->bill_status_name = '已打印生产单';
                        break;
                    case 3:
                        $bill->bill_status_name = '已质检入库';
                        break;
                    case 4:
                        $bill->bill_status_name = '已上车';
                        break;
                    case 5:
                        $bill->bill_status_name = '已下车';
                        break;
                    case 6:
                        $bill->bill_status_name = '已出仓';
                        break;
                    //mod by yim.hu 20141121 FUN-BK-0035-订单状态优化 --end
                    case 7:
                        $bill->bill_status_name = '已完成';
                        break;
                    case 10:
                        $bill->bill_status_name = '已取消';
                        break;
                    case 11:
                        $bill->bill_status_name = '异常订单';
                        break;
                    default:
                        $bill->bill_status_name = '';
                        break;
                }

                //配送状态
                switch ($bill->deliver_status) {
                    case '0':
                        $bill->deliver_status_name = '等待发货';
                        break;
                    case 1:
                        $bill->deliver_status_name = '部分已发货';
                        break;
                    case 2:
                        $bill->deliver_status_name = '全部已发货';
                        break;
                    case 3:
                        $bill->deliver_status_name = '已收货确认';
                        break;
                }

                //退货状态
                if( $bill->bill_withdrawAmount == $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '全部退货';
                }elseif ( $bill->bill_withdrawAmount > 0 && $bill->bill_withdrawAmount < $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '部分退货';
                }else{
                    $bill->bill_withdraw_name = '未退货';
                }

                //拒收状态
                if( $bill->bill_rejectionAmount == $bill->bill_totalAmount ){
                    $bill->bill_rejection_name = '全部拒收';
                }elseif ( $bill->bill_rejectionAmount > 0 && $bill->bill_rejectionAmount < $bill->bill_totalAmount ){
                    $bill->bill_rejection_name = '部分拒收';
                }else{
                    $bill->bill_rejection_name = '未拒收';
                }

                switch($bill->billType) {
                    case 1:
                        $bill->billTypeName = '普通订单';
                        break;
                    case 2:
                        $bill->billTypeName = '团购订单';
                        break;
                    case 3:
                        $bill->billTypeName = '秒杀订单';
                        break;
                    case 4:
                        $bill->billTypeName = '积分订单';
                        break;
                    case 5:
                        $bill->billTypeName = '补货单';
                        break;
                    case 6:
                        $bill->billTypeName = '换货单';
                        break;
                    default:
                        $bill->billTypeName = '';
                        break;
                }

                switch($bill->billPlatform) {
                    case 1:
                        $bill->billPlatformName = '自营';
                        break;
                    case 2:
                        $bill->billPlatformName = '天猫';
                        break;
                    case 3:
                        $bill->billPlatformName = '京东';
                        break;
                    case 4:
                        $bill->billPlatformName = '1号店';
                        break;
                    case 5:
                        $bill->billPlatformName = 'QQ网购';
                        break;
                    case 6:
                        $bill->billPlatformName = '凡客';
                        break;
                    case 7:
                        $bill->billPlatformName = '苏宁易购';
                        break;
                    case 8:
                        $bill->billPlatformName = '易讯';
                        break;
                    case 9:
                        $bill->billPlatformName = '拍拍';
                        break;
                    case 10:
                        $bill->billPlatformName = '亚马逊';
                        break;
                    case 11:
                        $bill->billPlatformName = '当当';
                        break;
                    case 12:
                        $bill->billPlatformName = '淘宝';
                        break;
                    case 13:
                        $bill->billPlatformName = '实体店';
                        break;
                    default:
                        $bill->billTypeName = '';
                        break;
                }

                switch($bill->billChannel) {
                    case 1:
                        $bill->billChannelName = 'web';
                        break;
                    case 2:
                        $bill->billChannelName = 'wap';
                        break;
                    case 3:
                        $bill->billChannelName = '微信';
                        break;
                    case 4:
                        $bill->billChannelName = 'app';
                        break;
                    case 5:
                        $bill->billChannelName = '线下';
                        break;
                    case 6:
                        $bill->billChannelName = '客服';
                        break;
                    default:
                        $bill->billChannelName = '';
                        break;
                }

                $item_array[] = array(
                    //订单信息
                    'bill_no' => (string)$bill->bill_no,
                    'uuid' => $bill->uuid,
                    'timeStamp' => $bill->timeStamp,
                    'creator' => $bill->creator,
                    'createTime' => $bill->createTime,
                    'bill_code' =>(string) $bill->bill_code,
                    'pcustID' => $bill->pcustID,
                    'custID' => $bill->custID,
                    'bill_status' => $bill->bill_status,
                    'billPlatform' => $bill->billPlatform,
                    'billPlatformName' => $bill->billPlatformName,
                    'billChannel' => $bill->billChannel,
                    'billChannelName' => $bill->billChannelName,
                    'billType' => $bill->billType,
                    'billTypeName' => $bill->billTypeName,
                    'bill_status_name' => $bill->bill_status_name,
                    'bill_cancel' => $bill->bill_cancel,
                    'bill_cancelTime' => $bill->bill_cancelTime,
                    'bill_totalMoney' => $bill->bill_totalMoney,
                    'bill_totalPaid' => $bill->bill_totalPaid,
                    'bill_totalPoints' => $bill->bill_totalPoints,
                    'bill_pointsPrice' => $bill->bill_pointsPrice,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'bill_withdraw_name' => $bill->bill_withdraw_name,
                    'bill_rejection_name' => $bill->bill_rejection_name,
                    'bill_subtract_money' => $bill->bill_subtract_money,
                    'bill_coupon_money' => $bill->bill_coupon_money,
                    'bill_accessories_money' => $bill->bill_accessories_money,
                    'bill_card_money' => $bill->bill_card_money,
                    'bill_points_money' => $bill->bill_points_money,
                    'bill_money'=>$bill->bill_money,
                    'bill_receivable_money' => $bill->bill_receivable_money,
                    'is_urgent' => $bill->is_urgent,
                    'is_reconciliation' => $bill->is_reconciliation,
                    'is_receivable' => $bill->is_receivable,

                    //收货人信息
                    'deliverid' => $bill->deliverid,
                    'deliver_name' => decryptD($bill->deliver_name),
                    'deliver_province' => $bill->deliver_province,
                    'deliver_provinceid' => $bill->deliver_provinceid,
                    'deliver_city' => $bill->deliver_city,
                    'deliver_cityid' => $bill->deliver_cityid,
                    'deliver_county' => $bill->deliver_county,
                    'deliver_countyid' => $bill->deliver_countyid,
                    'deliver_address' => decryptD($bill->deliver_address),
                    'deliver_all_address' => $bill->deliver_province . $bill->deliver_city . $bill->deliver_county . decryptD($bill->deliver_address),
                    'deliver_postalCode' => $bill->deliver_postalCode,
                    'deliver_mobile' => decryptD($bill->deliver_mobile),
                    'deliver_phone' => decryptD($bill->deliver_phone),

                    //配送
                    'distribution_id' => $bill->distribution_id,//配送站ID
                    'distribution_name' => $bill->distribution_name,//配送站名称
                    'distribution_technician_id' => $bill->distribution_technician_id,//配送站ID
                    'distribution_technicia' => $bill->distribution_technicia,//配送站名称
                    'sendTypeID' => $bill->sendTypeID, //配送方式ID
                    'sendTypeName' => $bill->sendTypeName, //配送方式名称
                    'send_region_name' => $bill->send_region_name, //配送区域名称
                    'send_region_id' => $bill->send_region_id, //配送区域ID
                    'deliver_fee' => $bill->deliver_fee, //应收运费
                    'deliver_feePaid' => $bill->deliver_feePaid, //实收运费
                    'deliver_status' => $bill->deliver_status, //配送状态
                    'deliver_status_name' => $bill->deliver_status_name, //配送状态
                    'deliver_time' => $bill->deliver_time, //配送状态变化时间
                    'send_date' => $bill->send_date,
                    'send_start_time' => $bill->send_start_time,
                    'send_end_time' => $bill->send_end_time,

                    //付款
                    'pay_status' => $bill->pay_status, //付款状态
                    'pay_status_name' => $bill->pay_status_name, //付款方式名称
                    'payed_time' => $bill->payed_time, //付款时间
                    'pay_type' => $bill->pay_type, //支付方式类型
                    'payTypeID' => $bill->payTypeID, //支付方式ID
                    'payment_method_id'=>$bill->payment_method_id,//
                    'payTypeName' => $bill->payTypeName, //支付方式名称
                    'payment_method_name'=>$bill->payment_method_name,//付款方式
                    //发票信息
                    'invoice' => $bill->invoice,
                    'invoiceID' => $bill->invoiceID,
                    'invoice_type' => $bill->invoice_type,
                    'invoice_title_type' => $bill->invoice_title_type,
                    'invoice_title' => $bill->invoice_title,
                    'invoice_content_id' => $bill->invoice_content_id,
                    'invoice_content' => $bill->invoice_content,
                    'invoice_amount' => $bill->invoice_amount,
                    'invoice_number' => $bill->invoice_number,

                    'print_num' => $bill->print_num,
                    'remark' => $bill->remark,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'external_bill_no' => $bill->external_bill_no,
                    'printTaskList_num'=>$bill->printTaskList_num,
                    'special_status'=>$bill->special_status,
                    'billPromotion'=>$bill->billPromotion,//促销渠道
                    'paying_agent_str'=>$bill->paying_agent_str,//代付订单
                    'goods_spec_str'=>$goods_spec_str
                );
            }

            return $item_array;

        } catch (Exception $e) {

            error_log($e->getMessage());
            return null;
        }


    }


    /**
     * //add by allen.qiang 20140925 加字段“配送员”
     * 查询订单配送员信息
     * @param $arg_bill_code
     * @return null|array
     */
    public function searchBilldistributionInfo( $arg_bill_code ) {
        global $G_SHOP;

        if (!isset($arg_bill_code) || empty($arg_bill_code)) {
            return null;
        }

        $search_sql = 'select distribution_technician_id ,distribution_technicia from bill_master where bill_code=\''.$arg_bill_code. '\'';
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql);
        $item_array = array();
        if (!$temp_item_array) {
            //无数据
            $item_array = array(
                'distribution_technician_id' =>'',                                      //配送员ID
                'distribution_technicia' => '',                                         //配送员名称
            );
            return $item_array;
        }

        foreach ($temp_item_array as $bill) {
            $item_array = array(
                'distribution_technician_id' => $bill->distribution_technician_id,  //配送员ID
                'distribution_technicia' => $bill->distribution_technicia,           //配送员名称
            );
        }
        return $item_array;
    }
    
   /**
    * 查询促销渠道
    * module
    * FUN-BK-0009_配送单优化
    * allen.qiang
    */
    public function searchPromotion($id){
        global $G_SHOP;
        //sql字符串
        $sql = '';
        //参数类型字符串
        $params_type = '';
        $sql .= ' AND itemID = ?';
        $params_type .= 'i';
        $params_array[] =$id;
        $sql = 'WHERE ' . substr($sql, 4);
        //参数值数组

    	$search_sql = "select itemName  from sys_item ".$sql;
    	$promotion_name =$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
    	return $promotion_name;
    	
    }


    /**
     * 订单结算时查询订单主表信息(根据条件查询全部，不分页)
     * @param $arg_array
     */
    public function searchSendBillGoods_res( &$arg_array ) {

        global $G_SHOP;

        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //订单流水号
        if (isset($arg_array['bill_no']) && is_numeric($arg_array['bill_no'])) {
            $sql .= ' AND bill_no = ?';
            $params_type .= 's';
            $params_array[] = trim($arg_array['bill_no']);
        }

        //订单号
        if (isset($arg_array['bill_code']) && is_numeric($arg_array['bill_code'])) {
            $sql .= ' AND bill_code LIKE ?';
            $params_type .= 's';
            $params_array[] = '%'.trim($arg_array['bill_code']);
        }

        //配送日期
        if (isset($arg_array['send_date']) && !empty($arg_array['send_date'])) {
            $sql .= ' AND send_date = ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_date'];
        }

        //配送开始时间
        if (isset($arg_array['send_start_time']) && !empty($arg_array['send_start_time'])) {
            $sql .= ' AND send_start_time >= ?';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time'];
        }

        //配送结束时间
        if (isset($arg_array['send_start_time_end']) && !empty($arg_array['send_start_time_end'])) {
            $sql .= ' AND send_start_time <= ?  ';
            $params_type .= 's';
            $params_array[] = $arg_array['send_start_time_end'];
        }

        //配送对账（是或否）
        if (isset($arg_array['is_reconciliation']) && is_numeric($arg_array['is_reconciliation'])) {
            $sql .= ' AND is_reconciliation = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['is_reconciliation'];
        }

        //财务对账（是或否）
        if (isset($arg_array['is_receivable']) && is_numeric($arg_array['is_receivable'])) {
            $sql .= ' AND is_receivable = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['is_receivable'];
        }

        //是否有应收
        if (isset($arg_array['receivable']) && is_numeric($arg_array['receivable'])) {
            if($arg_array['receivable'] == 1){
                $sql .= ' AND bill_receivable_money != "0.00" ';
            }else{
                $sql .= ' AND bill_receivable_money = "0.00" ';
            }

        }

        //城市

        $PS_LOGIN_SESSION = $G_SHOP->sessionCache_get('PS_LOGIN_SESSION');

        if (isset($arg_array['deliver_cityid']) && is_numeric($arg_array['deliver_cityid'])) {
            $sql .= ' AND deliver_cityid = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['deliver_cityid'];
        }else{
            if($PS_LOGIN_SESSION['city']){
                $city  = implode(",",$PS_LOGIN_SESSION['city']);
                $sql .=" AND deliver_cityid IN ( ".$city." )";
            }
        }

        //配送站
        if (isset($arg_array['distribution_id']) && is_numeric($arg_array['distribution_id'])) {
            $sql .= ' AND distribution_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_id'];
        }

        //配送员
        if (isset($arg_array['distribution_technician_id']) && is_numeric($arg_array['distribution_technician_id'])) {
            $sql .= ' AND distribution_technician_id = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['distribution_technician_id'];
        }

        //是否分配配送员
        if (isset($arg_array['technician_id']) && is_numeric($arg_array['technician_id'])) {
            if($arg_array['technician_id'] == 0){
                $sql .= ' AND distribution_technician_id = ?';
                $params_type .= 'i';
                $params_array[] = $arg_array['technician_id'];
            }else if($arg_array['technician_id'] == 1){
                $sql .= ' AND distribution_technician_id != ?';
                $params_type .= 'i';
                $params_array[] = 0;
            }
        }

        //订单类型
        if(isset($arg_array['bill_type']) && !empty($arg_array['bill_type'])){
            if(strpos($arg_array['bill_type'],'all') !== false){
                $sql .= " AND billType IN (1,2,3,4,5,6,7,8,9)";
            }else{
                $sql .= " AND billType IN ( ".$arg_array['bill_type']." )";
            }
        }

        //订单状态
        if(isset($arg_array['billStatus']) && !empty($arg_array['billStatus'])){
            if(strpos($arg_array['billStatus'],'all') !== false){
                $sql .= " AND bill_status IN (5,6,7)";
            }else{
                $sql .= " AND bill_status IN ( ".$arg_array['billStatus']." )";
            }
        }else{
            $sql .= " AND bill_status IN (5,6,7)";
        }

        //发票
        if (isset($arg_array['invoice']) && is_numeric($arg_array['invoice'])) {
            $sql .= ' AND invoice = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['invoice'];
        }

        //配送单是否打印
        if (isset($arg_array['print_num']) && is_numeric($arg_array['print_num'])) {
            if($arg_array['print_num'] == 1){
                $sql .= ' AND print_num > 0';
            }else{
                $sql .= ' AND print_num = 0';
            }
        }

        //是否打印配送任务清单
        if ( isset($arg_array['printTaskList_num']) && is_numeric($arg_array['printTaskList_num']) ) {
            if($arg_array['printTaskList_num'] == 1){
                $sql .= ' AND printTaskList_num > 0';
            }else{
                $sql .= ' AND printTaskList_num = 0';
            }
        }

        //订单平台
        if (isset($arg_array['billPlatform']) && is_numeric($arg_array['billPlatform'])) {
            $sql .= ' AND billPlatform = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['billPlatform'];
        }

        if (isset($arg_array['extend']) && !empty($arg_array['extend'])) {
            $sql .= $arg_array['extend'];
        }

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }

        try {

            //查询分类信息
            $search_sql = 'SELECT * FROM bill_master' . $sql;

            $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);

            if (!$temp_item_array) {
                return null;
            }

            foreach ($temp_item_array as $bill) {

                //订单状态
                switch ($bill->bill_status) {
                    case '0':
                        if ($bill->pay_type == 1 || $bill->pay_status == 1) {
                            $bill->bill_status_name = '待审核';
                        } else {
                            $bill->bill_status_name = '待付款';
                        }
                        break;
                    case 1:
                        $bill->bill_status_name = '已确认';
                        break;
                    //mod by yim.hu 20141121 FUN-BK-0035-订单状态优化 --start    
//                     case 2:
//                         $bill->bill_status_name = '已生产';
//                         break;
//                     case 3:
//                         $bill->bill_status_name = '已入库';
//                         break;
//                     case 4:
//                         $bill->bill_status_name = '已出库';
//                         break;
//                     case 5:
//                         $bill->bill_status_name = '配送站收货';
//                         break;
//                     case 6:
//                         $bill->bill_status_name = '已配送';
//                         break;

                    case 2:
                        $bill->bill_status_name = '已打印生产单';
                        break;
                    case 3:
                        $bill->bill_status_name = '已质检入库';
                        break;
                    case 4:
                        $bill->bill_status_name = '已上车';
                        break;
                    case 5:
                        $bill->bill_status_name = '已下车';
                        break;
                    case 6:
                        $bill->bill_status_name = '已出仓';
                        break;
                    //mod by yim.hu 20141121 FUN-BK-0035-订单状态优化 --end
                    case 7:
                        $bill->bill_status_name = '已完成';
                        break;
                    case 10:
                        $bill->bill_status_name = '已取消';
                        break;
                    case 11:
                        $bill->bill_status_name = '异常订单';
                        break;
                    default:
                        $bill->bill_status_name = '';
                        break;
                }

                //配送状态
                switch ($bill->deliver_status) {
                    case '0':
                        $bill->deliver_status_name = '等待发货';
                        break;
                    case 1:
                        $bill->deliver_status_name = '部分已发货';
                        break;
                    case 2:
                        $bill->deliver_status_name = '全部已发货';
                        break;
                    case 3:
                        $bill->deliver_status_name = '已收货确认';
                        break;
                }

                //退货状态
                if( $bill->bill_withdrawAmount == $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '全部退货';
                }elseif ( $bill->bill_withdrawAmount > 0 && $bill->bill_withdrawAmount < $bill->bill_totalAmount ){
                    $bill->bill_withdraw_name = '部分退货';
                }else{
                    $bill->bill_withdraw_name = '未退货';
                }

                //拒收状态
                if( $bill->bill_rejectionAmount == $bill->bill_totalAmount ){
                    $bill->bill_rejection_name = '全部拒收';
                }elseif ( $bill->bill_rejectionAmount > 0 && $bill->bill_rejectionAmount < $bill->bill_totalAmount ){
                    $bill->bill_rejection_name = '部分拒收';
                }else{
                    $bill->bill_rejection_name = '未拒收';
                }

                switch($bill->billType) {
                    case 1:
                        $bill->billTypeName = '普通订单';
                        break;
                    case 2:
                        $bill->billTypeName = '团购订单';
                        break;
                    case 3:
                        $bill->billTypeName = '秒杀订单';
                        break;
                    case 4:
                        $bill->billTypeName = '积分订单';
                        break;
                    case 5:
                        $bill->billTypeName = '补货单';
                        break;
                    case 6:
                        $bill->billTypeName = '换货单';
                        break;
                    default:
                        $bill->billTypeName = '';
                        break;
                }

                switch($bill->billPlatform) {
                    case 1:
                        $bill->billPlatformName = '自营';
                        break;
                    case 2:
                        $bill->billPlatformName = '天猫';
                        break;
                    case 3:
                        $bill->billPlatformName = '京东';
                        break;
                    case 4:
                        $bill->billPlatformName = '1号店';
                        break;
                    case 5:
                        $bill->billPlatformName = 'QQ网购';
                        break;
                    case 6:
                        $bill->billPlatformName = '凡客';
                        break;
                    case 7:
                        $bill->billPlatformName = '苏宁易购';
                        break;
                    case 8:
                        $bill->billPlatformName = '易讯';
                        break;
                    case 9:
                        $bill->billPlatformName = '拍拍';
                        break;
                    case 10:
                        $bill->billPlatformName = '亚马逊';
                        break;
                    case 11:
                        $bill->billPlatformName = '当当';
                        break;
                    case 12:
                        $bill->billPlatformName = '淘宝';
                        break;
                    case 13:
                        $bill->billPlatformName = '实体店';
                        break;
                    default:
                        $bill->billTypeName = '';
                        break;
                }

                switch($bill->billChannel) {
                    case 1:
                        $bill->billChannelName = 'web';
                        break;
                    case 2:
                        $bill->billChannelName = 'wap';
                        break;
                    case 3:
                        $bill->billChannelName = '微信';
                        break;
                    case 4:
                        $bill->billChannelName = 'app';
                        break;
                    case 5:
                        $bill->billChannelName = '线下';
                        break;
                    case 6:
                        $bill->billChannelName = '客服';
                        break;
                    default:
                        $bill->billChannelName = '';
                        break;
                }

                $item_array[] = array(
                    //订单信息
                    'bill_no' => (string)$bill->bill_no,
                    'uuid' => $bill->uuid,
                    'timeStamp' => $bill->timeStamp,
                    'creator' => $bill->creator,
                    'createTime' => $bill->createTime,
                    'bill_code' =>(string) $bill->bill_code,
                    'pcustID' => $bill->pcustID,
                    'custID' => $bill->custID,
                    'bill_status' => $bill->bill_status,
                    'billPlatform' => $bill->billPlatform,
                    'billPlatformName' => $bill->billPlatformName,
                    'billChannel' => $bill->billChannel,
                    'billChannelName' => $bill->billChannelName,
                    'billType' => $bill->billType,
                    'billTypeName' => $bill->billTypeName,
                    'bill_status_name' => $bill->bill_status_name,
                    'bill_cancel' => $bill->bill_cancel,
                    'bill_cancelTime' => $bill->bill_cancelTime,
                    'bill_totalMoney' => $bill->bill_totalMoney,
                    'bill_money' => $bill->bill_money,
                    'bill_received_money' => $bill->bill_received_money,
                    'bill_receivable_money' => $bill->bill_receivable_money,
                    'bill_totalPaid' => $bill->bill_totalPaid,
                    'bill_totalPoints' => $bill->bill_totalPoints,
                    'bill_pointsPrice' => $bill->bill_pointsPrice,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'bill_withdraw_name' => $bill->bill_withdraw_name,
                    'bill_rejection_name' => $bill->bill_rejection_name,
                    'bill_subtract_money' => $bill->bill_subtract_money,
                    'bill_coupon_money' => $bill->bill_coupon_money,
                    'bill_accessories_money' => $bill->bill_accessories_money,
                    'bill_card_money' => $bill->bill_card_money,
                    'bill_points_money' => $bill->bill_points_money,
                    'bill_balance_money' => $bill->bill_balance_money,
                    'bill_online_money' => $bill->bill_online_money,
                    'is_urgent' => $bill->is_urgent,
                    'is_reconciliation' => $bill->is_reconciliation,
                    'is_receivable' => $bill->is_receivable,
                    'pay_id_str' =>$bill->pay_id_str,
                    'pay_name_str' =>$bill->pay_name_str,
                    'bill_reject_cause' =>$bill->bill_reject_cause,

                    //收货人信息
                    'deliverid' => $bill->deliverid,
                    'deliver_name' => decryptD($bill->deliver_name),
                    'deliver_province' => $bill->deliver_province,
                    'deliver_provinceid' => $bill->deliver_provinceid,
                    'deliver_city' => $bill->deliver_city,
                    'deliver_cityid' => $bill->deliver_cityid,
                    'deliver_county' => $bill->deliver_county,
                    'deliver_countyid' => $bill->deliver_countyid,
                    'deliver_address' => decryptD($bill->deliver_address),
                    'deliver_all_address' => $bill->deliver_province . $bill->deliver_city . $bill->deliver_county . decryptD($bill->deliver_address),
                    'deliver_postalCode' => $bill->deliver_postalCode,
                    'deliver_mobile' => decryptD($bill->deliver_mobile),
                    'deliver_phone' => decryptD($bill->deliver_phone),

                    //配送
                    'distribution_id' => $bill->distribution_id,//配送站ID
                    'distribution_name' => $bill->distribution_name,//配送站名称
                    'distribution_technician_id' => $bill->distribution_technician_id,//配送站ID
                    'distribution_technicia' => $bill->distribution_technicia,//配送站名称
                    'sendTypeID' => $bill->sendTypeID, //配送方式ID
                    'sendTypeName' => $bill->sendTypeName, //配送方式名称
                    'send_region_name' => $bill->send_region_name, //配送区域名称
                    'send_region_id' => $bill->send_region_id, //配送区域ID
                    'deliver_fee' => $bill->deliver_fee, //应收运费
                    'deliver_feePaid' => $bill->deliver_feePaid, //实收运费
                    'deliver_status' => $bill->deliver_status, //配送状态
                    'deliver_status_name' => $bill->deliver_status_name, //配送状态
                    'deliver_time' => $bill->deliver_time, //配送状态变化时间
                    'send_date' => $bill->send_date,
                    'send_start_time' => $bill->send_start_time,
                    'send_end_time' => $bill->send_end_time,

                    //付款
                    'pay_status' => $bill->pay_status, //付款状态
                    'pay_status_name' => $bill->pay_status_name, //付款方式名称
                    'payed_time' => $bill->payed_time, //付款时间
                    'pay_type' => $bill->pay_type, //支付方式类型
                    'payTypeID' => $bill->payTypeID, //支付方式ID
                    'payTypeName' => $bill->payTypeName, //支付方式名称

                    //发票信息
                    'invoice' => $bill->invoice,
                    'invoiceID' => $bill->invoiceID,
                    'invoice_type' => $bill->invoice_type,
                    'invoice_title_type' => $bill->invoice_title_type,
                    'invoice_title' => $bill->invoice_title,
                    'invoice_content_id' => $bill->invoice_content_id,
                    'invoice_content' => $bill->invoice_content,
                    'invoice_amount' => $bill->invoice_amount,
                    'invoice_number' => $bill->invoice_number,

                    'remark' => $bill->remark,
                    'bill_totalAmount' => $bill->bill_totalAmount,
                    'bill_withdrawAmount' => $bill->bill_withdrawAmount,
                    'bill_rejectionAmount' => $bill->bill_rejectionAmount,
                    'external_bill_no' => $bill->external_bill_no

                );
            }

            return $item_array;

        } catch (Exception $e) {

            error_log($e->getMessage());
            return null;
        }

    }


    /**
     * 查询订单抹去金额小数部分
     * @param array $arg_array
     * @return null|array
     * @author create by allen.qiang
     */
    public function searchEraseMney( &$arg_array ) {

        if (!isset($arg_array['bill_no']) || empty($arg_array['bill_no'])) {
            return null;
        }

        global $G_SHOP;

        //sql字符串
        $sql = 'bill_no = ?';

        //参数类型字符串
        $params_type = 's';

        //参数值数组
        $params_array = array( $arg_array['bill_no'] );

        $sql .= ' ORDER BY createTime ASC';

        //查询分类信息
        $search_sql = 'SELECT * FROM bill_erase_decimals_money WHERE ' . $sql;
        $temp_item_array = $G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();
        foreach ($temp_item_array as &$item) {
            $item_array[] = array(
                'creator' => $item->creator,
                'createTime' => $item->createTime,
                'bill_no' => $item->bill_no,
                'erase_money' => $item->erase_money
            );
        }

        return $item_array;
    }
}